I am not able to understand why I am getting a Type Error for the following statement
log.debug('vec : %s blasted : %s\n' %(str(vec), str(bitBlasted)))
type(vec) is unicode
bitBlasted is a list
I am getting the following error
TypeError: 'str' object is not callable
Shadowing the built-in
Either as Collin said, you could be shadowing the built-in
str:One solution would be to change the variable name to
str_or something. A better solution would be to avoid this kind of Hungarian naming system — this isn’t Java, use Python’s polymorphism to its fullest and use a more descriptive name instead.Not defining a proper method
Another possibility is that the object may not have a proper
__str__method or even one at all.The way Python checks for the
strmethod is:-__str__method of the class__str__method of its parent class__repr__method of the class__repr__method of its parent class<module>.<classname> instance at <address>where<module>isself.__class__.__module__,<classname>isself.__class__.__name__and<address>isid(self)Even better than
__str__would be to use the new__unicode__method (in Python 3.x, they’re__bytes__and__str__. You could then implement__str__as a stub method:See this question for more details.