简体   繁体   中英

'str' object is not callable using enumerate

I'm trying to do the following:

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

But I keep getting

TypeError at /
'str' object is not callable

What is going wrong here?

As the commenters have mentioned, you must have str defined somewhere and it overrides the str built-in function.

In Python you can easily "re-bind" symbols like this. See this session for example:

>>> 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

Moreover the text of your TypeError suggests that str was defined to be a string object somewhere earlier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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