Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Notes.py命令出错_Python - Fatal编程技术网

Python Notes.py命令出错

Python Notes.py命令出错,python,Python,我正在尝试使用以下代码(): 当我运行它时,它会给出一个错误,告诉我它需要超过1个值来为sender、message、rawtime解包,用l:Oh l应该=['sender','message',rawtime] 如何解决此问题?您的列表仅包含3项,因此不需要循环。只要做: >>> lis = ['sender', 'message', 'rawtime'] >>> sender, message, rawtime = lis >>> se

我正在尝试使用以下代码():

当我运行它时,它会给出一个错误,告诉我它需要超过1个值来为sender、message、rawtime解包,用l:Oh l应该=['sender','message',rawtime]


如何解决此问题?

您的列表仅包含3项,因此不需要循环。只要做:

>>> lis = ['sender', 'message', 'rawtime']
>>> sender, message, rawtime = lis
>>> sender
'sender'
>>> message
'message'
>>> rawtime
'rawtime'
如果要使用for循环,请使用列表列表或元组列表:

>>> lis = [('sender', 'message', 'rawtime')]
>>> for x, y, z in lis:
...     print x, y, z
...     
sender message rawtime
更新:代码的固定版本:

for sender, message, rawtime in notes.one(user.name):
        room.message("Note from %s: %s [%s] " % sender, message, self.LongTimeStampFull(rawtime))

太多的物品无法打开意味着你的清单比你想象的要长。例如:
a,b=(1,2,3)
。那么就做notes吧。一个(user.name)=[('sender'、'message'、'rawtime')]notes。一个(user.name)从数据库中检索列表。它没有工作lol。它给出了“太多的值要解包(预期3)@user2950638
notes.one(user.name)
返回什么?
for sender, message, rawtime in notes.one(user.name):
        room.message("Note from %s: %s [%s] " % sender, message, self.LongTimeStampFull(rawtime))