-1

Possible Duplicate:
TypeError: 'str' object is not callable (Python)

I'm torchuring Python 3.2.3. But my textbook is about 2.7 and 3.0. Judging from the textbook this is pretty Ok:

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

Why should my Python shout: TypeError: 'str' object is not callable

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Kifsif
  • 3,477
  • 10
  • 36
  • 45

2 Answers2

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)
Tim Lamballais
  • 1,056
  • 5
  • 10
0

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

CharlesB
  • 86,532
  • 28
  • 194
  • 218