我有一个简单的函数,下面是
comdList = range(0,27)
for t, in comdList:
print t
但是它返回一个 in object not iterable 错误
在函数之外它工作正常。怎么回事??
最佳答案
试试这个:
for t in comdList:
print t
t
变量后的额外逗号导致错误,因为它 Python 认为可迭代对象将返回一元组序列以解包 - 例如:( (1,), (2,))
但它收到了一个可迭代的单个元素。
关于函数中的python对象不可迭代错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17226331/