-1

可能重复:
TypeError:“str”对象不可调用(Python)

我正在烧毁 Python 3.2.3。但我的教科书大约是2.7和3.0。从教科书来看,这还不错:

dict1 = {'one':1, 'two':2, 'three': {'three.1': 3.1, 'three.2': 3.2 }}
str1 = str(dict1)

为什么我的 Python 应该大喊:TypeError: 'str' object is not callable

4

2 回答 2

2

You probably instantiated an object called 'str' earlier. This would result in the given error.

Python lets you override the type object str (meaning strings) without warning.

For example, the following code would produce your error:

str = 'foo'
dict1 = {'one':1, 'two':2, 'three': {'three.1': 3.1, 'three.2': 3.2 }}
str1 = str(dict1)
于 2012-09-20T12:19:28.697 回答
0

You may have defined a variable called str before, conflicting with the str() function

于 2012-09-20T12:18:51.750 回答