Reputation: 4253
Using Python 2.5.2 (r252:60911, Sep 30 2008, 15:42:03) I try to use
type(x)
and receive the following error when passing in this string '2014-02-06 00:00:00'
TypeError: 'str' object is not callable
why does it not return str?
Upvotes: 1
Views: 86
Reputation: 48745
You probably shadowed the python function type
with a string by doing the following:
>>> type = 'some string'
>>> # Lots of code
>>> x = 'other string'
>>> type(x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable
You can fix this by not using variable names that are also python builtin functions.
If you absolutely cannot rename your variable to be something other than type
(_type
or type_
will do), you can access the builtin function using the __builtin__
module
>>> type = 'some string'
>>> # Lots of code
>>> x = 'other string'
>>> import __builtin__
>>> __builtin__.type(x)
<type 'str'>
Anyone reading your code will hate you, though.
Upvotes: 6