我正在创建压缩文件/文件夹的Python软件......我如何创建一段代码,要求用户输入文件夹位置然后压缩它.我目前有单个文件的代码,但不是一个文件夹.请详细说明如何执行此操作.
我正在尝试安装Evennia Python MUD,当我到达python manage.py syncdb命令时,我得到以下消息...有关为什么的任何想法?
Traceback (most recent call last):
File "evennia.py", line 33, in ?
from django.conf import settings
ImportError: No module named django.conf
Run Code Online (Sandbox Code Playgroud) 我正在尝试为Python安装zope接口脚本.但是,我看到的唯一下载是.egg文件类型.我正在运行Windows Python 2.7,我应该把这个文件放在Zope接口上,以便与我的Python一起正常工作?
让我们假设我有一些RPG的功能我正在努力......
def name_of_function():
action
Run Code Online (Sandbox Code Playgroud)
并希望在每个函数中实现ax类(见下文),而不必重写每个类.我如何将该类创建为全局类.我不确定我是否使用了正确的术语,但请帮忙.这总是让我难以创建基于文本的RPG游戏.一个全球类的例子真棒!
class axe:
attack = 5
weight = 6
description = "A lightweight battle axe."
level_required = 1
price = 10
Run Code Online (Sandbox Code Playgroud) 我在使用Python读取文本文件的整个特定行时遇到问题.我目前有这个:
load_profile = open('users/file.txt', "r")
read_it = load_profile.readline(1)
print read_it
Run Code Online (Sandbox Code Playgroud)
当然这只会读取第一行的一个字节,这不是我想要的.我也试过谷歌,但没有找到任何东西.
让我们说我必须变量,狗和猫.Dog = 5,cat = 3.我如何告诉Python随机选择其中一个变量并将其打印到屏幕上?
我正在使用Twisted库在Python中编写MUD.我目前正在尝试通过sendLine方法将整数发送到LineReceiver模块.但是,每当我尝试发送一个整数时,我在运行程序时会收到以下错误消息:
Unhandled Error
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\twisted\python\log.py", line 84, in
thLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\log.py", line 69, in
thContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\context.py", line 118
allWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\context.py", line 81,
llWithContext
return func(*args,**kw)
--- <exception caught here> ---
File "C:\Python27\lib\site-packages\twisted\internet\selectreactor.py",
46, in _doReadOrWrite
why = getattr(selectable, method)()
File "C:\Python27\lib\site-packages\twisted\internet\tcp.py", line 460,
ead
rval = self.protocol.dataReceived(data)
File "C:\Python27\lib\site-packages\twisted\protocols\basic.py", line 56
dataReceived
why = self.lineReceived(line)
File …Run Code Online (Sandbox Code Playgroud) 我如何更改下面的代码,以便Python读取两个变量中的列表然后执行操作而不会发生错误?我的代码:
bad = ['bad','terrible', 'dumb']
good = ['good','happy','awesome']
talk = raw_input("type:")
if (bad) in talk:
print "I'm sorry to hear that :("
elif (good) in talk:
print "That's good!"
Run Code Online (Sandbox Code Playgroud) 而不是用户必须使用script.py --file c:/stuff/file.txt有一种方法让用户可选地使用--file?所以相反,它看起来像script.py c:/stuff/file.txt但解析器仍然知道用户正在引用--file参数(因为它暗示).