Built-in shading
Or, as Colleen said , you can obscure the built-in str:
>>> str = some_variable_or_string
>>> str(123.0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable
One solution would be to change the name of the variable to str_or something else. The best solution would be to avoid such a Hungarian naming system - this is not Java, use Python polymorphism in its entirety, and use a more descriptive name instead.
The correct method is not defined
Another possibility is that the object may not have the proper method __str__or even one.
, Python str: -
__str____str____repr____repr__- :
<module>.<classname> instance at <address>, <module> self.__class__.__module__, <classname> is self.__class__.__name__ <address> is id(self)
, __str__, __unicode__ ( Python 3.x, __bytes__ __str__. __str__ :
class foo:
...
def __str__(self):
return unicode(self).encode('utf-8')
. .