我一直在为工作中的简单任务制作Python脚本,从来没有真正打扰包装它们以供其他人使用.现在我被分配为REST API创建一个Python包装器.我完全不知道如何开始,我需要帮助.
是)我有的:
(只是想尽可能具体)我已经准备好了virtualenv,它也在github中,python的.gitignore文件也是,还有用于与REST API交互的请求库.而已.
这是当前目录树
.
??? bin
? ??? /the usual stuff/
??? include
? ??? /the usual stuff/
??? lib
? ??? python2.7
? ??? /the usual stuff/
??? local
? ??? /the usual stuff/
??? README.md
27 directories, 280 files
Run Code Online (Sandbox Code Playgroud)
我甚至不知道把.py文件放到哪里,如果我做的话.
我想做什么:
使用"pip install ..."安装python模块
如果可能的话,我想要编写Python模块的一般步骤.
解析Python命令行参数的最简单,最简洁,最灵活的方法或库是什么?
我最近遇到了一个我以前从未见过的语法,当我学习python时,在大多数教程中都没有,..
符号,它看起来像这样:
f = 1..__truediv__ # or 1..__div__ for python 2
print(f(8)) # prints 0.125
Run Code Online (Sandbox Code Playgroud)
我认为它完全相同(当然除了它更长):
f = lambda x: (1).__truediv__(x)
print(f(8)) # prints 0.125 or 1//8
Run Code Online (Sandbox Code Playgroud)
但我的问题是:
这可能会在将来为我节省很多代码...... :)
我安装了Python 3.x(除了Ubuntu上的Python 2.x)并慢慢开始配对我在Python 2.x中使用的模块.
所以我想知道,对于Python 2.x和Python 3.x,我应该采用什么方法让pip变得简单?
我在Mac OS中比较新.我刚刚安装了XCode(用于c ++编译器)和Anaconda用最新的Python 3(我自己).现在我想知道如何使用Python 2正确安装第二个Anaconda(用于工作)?
我需要两个版本才能使用iPython和Spyder IDE.理想的方法是拥有完全独立的Python环境.例如,我希望我可以像conda install scikit-learn
Python 3环境一样编写,就像conda2 install scikit-learn
Python 2一样.
我运行了以下命令:
easy_install pip
sudo pip install setuptools --no-use-wheel --upgrade
Run Code Online (Sandbox Code Playgroud)
如何反转这两个命令以使我的python在OSX中恢复到原始状态?(删除pip作为其中的一部分)
我正在尝试使用Python编写discord机器人,我遇到了这个机器人.
import discord
import asyncio
import random
client = discord.Client()
inEmail = input("Email:")
inPassword = input("Passwd:")
async def background_loop():
await client.wait_until_ready()
while not client.is_closed:
channel = client.get_channel("************")
messages = ["Hello!", "How are you doing?", "Testing!!"]
await client.send_message(channel, random.choice(messages))
await asyncio.sleep(120)
client.loop.create_task(background_loop())
client.run(inEmail, inPassword)
Run Code Online (Sandbox Code Playgroud)
然而,当我试图运行它时,我收到了SyntaxError
:
File "1.py", line 7
async def background_loop():
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
这是为什么?我测试之前从未收到过.
我正在尝试使用pip安装pandas来运行一些基于pandas的Python程序.我已经安装了pip.我尝试使用谷歌搜索和SO'ing但没有找到解决此错误的方法.有人可以分享你的意见吗?
C:\> pip install pandas
Run Code Online (Sandbox Code Playgroud)
错误:
pip is not recognized as an internal or external command, operable program or batch file.
Run Code Online (Sandbox Code Playgroud) 我正在尝试用python设置一个discord bot.我有一个预先存在的discord服务器,我希望机器人加入,但我很难这样做.
import discord
import asyncio
import logging
logging.basicConfig(level=logging.INFO)
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
print(client)
@client.event
async def on_message(message):
print(message)
if message.content.startswith('!test'):
counter = 0
tmp = await client.send_message(message.channel, 'Calculating messages...')
async for log in client.logs_from(message.channel, limit=100):
if log.author == message.author:
counter += 1
await client.edit_message(tmp, 'You have {} messages.'.format(counter))
elif message.content.startswith('!sleep'):
await asyncio.sleep(5)
await client.send_message(message.channel, 'Done sleeping')
client.run('token')
Run Code Online (Sandbox Code Playgroud)
这基本上是GitHub页面上给出的基本discord.py脚本.但是,我似乎无法弄清楚如何让它实际加入我的服务器.将此行插入on_ready
函数时:
server = await client.accept_invite('instant-invite-code')
Run Code Online (Sandbox Code Playgroud)
将"即时邀请代码"替换为我的实际即时邀请代码(我尝试了discord.gg/code和代码),我得到了
discord.errors.Forbidden: FORBIDDEN (status code: 403): …
Run Code Online (Sandbox Code Playgroud) 推送后我一直在远程存储库中看到此消息:
1在master后面提交.
此合并具有必须在提交之前解决的冲突.
要手动将这些更改合并到TA20footerLast,请运行以下命令:
> git checkout 7c891f50c557
#注意:这将创建一个独立的头!
> git merge remotes/origin/master
git github bitbucket branching-and-merging git-merge-conflict
python ×9
pip ×3
discord ×2
discord.py ×2
macos ×2
python-2.7 ×2
python-3.x ×2
syntax ×2
anaconda ×1
async-await ×1
bitbucket ×1
cmd ×1
command-line ×1
git ×1
github ×1
operators ×1
pandas ×1
python-2.x ×1
windows ×1