0
我試圖做到以下幾點:「STR」對象不是可調用使用枚舉
for index, image_properties in enumerate(list_of_properties):
index = str(index)
但我不斷收到
TypeError at/
'str' object is not callable
這是怎麼回事錯在這裏?
我試圖做到以下幾點:「STR」對象不是可調用使用枚舉
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
被定義爲一個字符串對象的地方更早。
您是否有一個名字爲str的變量?因爲這就是它的樣子。例如:'str =「red」; str(1)'返回確切的錯誤。 – Josiah
@Josiah我同意,嘗試重新打開你的解釋器,並小心不要爲你的變量使用「內置」名稱。 – jamylak
如果您不想重新啓動解釋器,請嘗試'str = __builtins __。str' –