How Can I Fixtypeerror: 'str' Object Is Not Callable?
Solution 1:
You've overwritten the built-in list
function with a string:
list=l.pop()
To fix this, use a different variable name, other than list
. In general, you'll want to avoid shadowing built-ins when naming your variables. That is, don't name things list
, map
, dict
, etc.
It's also good practice to name your variables after what's in them. So if you have list = ["apples", "oranges", "pears"]
, you might consider renaming it fruits = ["apples", "oranges", "pears"]
. It really helps with code readability.
Solution 2:
You've defined list
to be a string:
list=l.pop()
So
list(zip(symbols,deck))
causes Python to complain that list
is not callable.
The solution, of course, is to use descriptive variable names that do not shadow Python builtins.
Solution 3:
This happened to me recently where I tried to call a function I had defined from within another function, but didn't notice that I also had a local variable in the calling fucntion with the same name as the function I was trying to call.
Due to the scope rules the call to the function was being interpreted as calling the local variable...hence the error message since a scalar variable of type 'str' (for example) is not callable.
So the essence of the problem is variables sharing the names of functions you need to call within their scope, whether they be functions you've defined, those included in imported modules or Python built-ins.
Post a Comment for "How Can I Fixtypeerror: 'str' Object Is Not Callable?"