我正在烧毁 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
我正在烧毁 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
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)
You may have defined a variable called str
before, conflicting with the str()
function