Code:
import urllib2 as u
import os as o
inn = \'dword.txt\'
w = open(inn)
z = w.readline()
b = w.readline()
c = w.readline()
x = w.readline
It is important to note (in case you came here by Google) that "TypeError: 'str' object is not callable" means only that a variable that was declared as String-type earlier is attempted to be used as a function (e.g. by adding parantheses in the end.)
You can get the exact same error message also, if you use any other built-in method as variable name.
In my case I had a class that had a method and a string property of the same name, I was trying to call the method but was getting the string property.
it could be also you are trying to index in the wrong way:
a = 'apple'
a(3) ===> 'str' object is not callable
a[3] = l
I had yet another issue with the same error!
Turns out I had created a property on a model, but was stupidly calling that property with parentheses.
Hope this helps someone!
Check your input parameters, and make sure you don't have one named type
. If so then you will have a clash and get this error.
Another case of this: Messing with the __repr__
function of an object where a format()
call fails non-transparently.
In our case, we used a @property
decorator on the __repr__
and passed that object to a format()
. The @property
decorator causes the __repr__
object to be turned into a string, which then results in the str
object is not callable error.