Shoken Startup Blog

KitchHike Founder/CTO

'str' object is not callable

'str' object is not callable というエラーでつまった。

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable

解決方法


strという変数を作らない

>>> d=1234
>>> str=str(d)
>>> print str
1234
>>> str=str(d)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable

1回目は、エラーが出ないのだが、すぐ後に、もう一度呼ぶと、エラーになる。

>>> d=1234
>>> f=str(d)
>>> print f
1234
>>> f=str(d)
>>> print f
1234

変数名に'str'を使わなければ、エラーは出ない。