Python 'list' 对象不可调用

标签 python pyscripter

我尝试在 Pyscripter 中运行以下代码,但它一直返回错误“'list' object is not callable”。我通过 Python shell 运行代码,它运行得非常好。我不太明白为什么它在 Pyscripter 中不起作用。另外,我使用的是 Python 2.7。

import itertools
print list(itertools.permutations([1,2,3,4], 2))

即使在 Pyscripter 中创建一个简单的列表也会返回同样的错误。

list()

提前致谢!

最佳答案

几乎可以肯定,您已将名称列表重新绑定(bind)到列表实例:

>>> import itertools
>>> print list(itertools.permutations([1,2,3,4], 2))
[(1, 2), (1, 3), (1, 4), (2, 1), (2, 3), (2, 4), (3, 1), (3, 2), (3, 4), (4, 1), (4, 2), (4, 3)]
>>> 
>>> list = [2,3,4]
>>> list(itertools.permutations([1,2,3,4], 2))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'list' object is not callable

不要调用列表 list 或字符串 str 等。

关于Python 'list' 对象不可调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10886003/

相关文章:

python - PyScripter 帮助文档丢失?

python - 类型错误 : 'str' object is not callable?

opencv - 在 PyScripter 中为 OpenCV 添加自动完成功能

python - 不断报错 incompatible library version libchtslib.so requires version 9.0.0 or later, but libcurl.4.dylib provides version 7.0.0

python - Psychopy记录最后一次鼠标滚轮移动的时间

python - UnicodeEncodeError : 'ascii' codec can't encode character u'\u201c' in position 34: ordinal not in range(128)

python - 尝试使用 pip 安装 PIL 时出错以及 pyscripter 错误

python用函数替换打印

python - Pandas to_dict 不希望地修改 float

python - 如何在 Python 3.x 中检查字符串中的新行?