繁体   English   中英

不能使用枚举调用“ str”对象

[英]'str' object is not callable using enumerate

我正在尝试执行以下操作:

for index, image_properties in enumerate(list_of_properties):
    index = str(index)

但我不断

TypeError at /
'str' object is not callable

这是怎么了?

正如评论者所提到的,您必须在某处定义str ,并且它会覆盖str内置函数。

在Python中,您可以像这样轻松地“重新绑定”符号。 例如,请参阅此会话:

>>> str(2)
'2'
>>> def str(x): return x + 1
... 
>>> str(2)
3
>>> str = 1
>>> str(2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable

此外, 您的 TypeError文本建议将str定义为较早位置的字符串对象。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM