Skip to content
Happy Programming Guide
Start learning
Python

Fixing “TypeError: object is not callable” in Python (Including list is not callable)

You put call brackets after something that is not a function. The type in the message names it. The usual cause is a variable that shadows a built-in or a function.

An open laptop on a wooden desk

TypeError: 'list' object is not callable means the code did something(...) and something was a list. Lists cannot be called, so Python stops. The type in the quotes tells you what the value really was, and in most cases the reason it was that type is that a name you meant to be a function has been overwritten with data — very often by shadowing a built-in such as list, str or print.

‘list’ object is not callable: a shadowed built-in#

Python
list = [1, 2, 3]            # the name list now means this list, not the built-in type
numbers = list(range(5))    # TypeError: 'list' object is not callable

Naming a variable list, str, dict, int, max, sum, input, type or print replaces the built-in for the rest of that scope. Everything works until the next time the built-in is needed. The error appears far from the cause, which is why it is confusing.

Search the file for an assignment to the name in the message:

Terminal
grep -n "^\s*list\s*=" script.py
grep -n "for list in\|def .*(list" script.py       # loop variables and parameters count too

Rename the variable — items, names, values — and the built-in comes back. In an interactive session, del list restores it without restarting.

‘module’ object is not callable#

Python
import datetime
now = datetime()             # TypeError: 'module' object is not callable
now = datetime.datetime.now()   # the class is inside the module

import json
data = json("...")           # TypeError - json is a module; the function is json.loads

A module and the thing inside it that you wanted have the same name, and you imported the outer one. Either import the inner name, from datetime import datetime, or use the dotted form.

Round brackets instead of square#

Python
scores = [70, 85, 90]
first = scores(0)            # TypeError: 'list' object is not callable
first = scores[0]

config = {"debug": True}
config("debug")              # TypeError: 'dict' object is not callable
config["debug"]

Indexing uses square brackets. This one is a typo, and the fix is the shape of the brackets.

‘str’ object is not callable#

Python
name = "Ada"
greeting = "Hello " name     # SyntaxError, so people "fix" it to:
greeting = "Hello "(name)    # TypeError: 'str' object is not callable
greeting = "Hello " + name   # what was meant

str = "some text"            # shadowing again
str(42)                      # TypeError

Python does not multiply or concatenate by putting things next to each other. A string followed by brackets is an attempt to call the string.

Calling something that is an attribute, not a method#

Python
class User:
    def __init__(self, name):
        self.name = name

u = User("Ada")
u.name()                     # TypeError: 'str' object is not callable - name is data

class Circle:
    def __init__(self, r):
        self.r = r
    @property
    def area(self):
        return 3.14159 * self.r ** 2

Circle(2).area()             # TypeError: 'float' object is not callable - area is a property
Circle(2).area               # 12.566

Properties and plain attributes are accessed without brackets. If the class defines it with @property, or sets it in __init__, do not call it.

A method and an attribute with the same name#

Python
class Counter:
    def __init__(self):
        self.count = 0          # attribute named count...

    def count(self):            # ...and a method named count: the attribute wins after __init__
        return self.count

Counter().count()            # TypeError: 'int' object is not callable

Instance attributes shadow methods of the same name. Rename one of them.

Calling an instance#

Python
class Greeter:
    def __init__(self, greeting):
        self.greeting = greeting

g = Greeter("Hi")
g("Ada")                     # TypeError: 'Greeter' object is not callable

Instances are not callable unless the class defines __call__. Either call a method, g.greet("Ada"), or add __call__ if calling the instance is genuinely the interface you want.

Finding the cause fast#

Python
print(type(thing), repr(thing))     # on the line before the failure

Then find where thing was last assigned. For a shadowed built-in, the assignment is usually near the top of the function or the file, sometimes in a loop header. Editors and linters flag shadowing of built-ins as a warning; turning that warning on catches this whole category before it runs.

Questions people ask#

Why does Python let me overwrite a built-in?

Built-ins are ordinary names in an outer scope, not reserved words. Any name you assign in your scope takes precedence. Flexibility, at the cost of this error.

The error names a type I never used.

Then a function you called returned that type and you called the result. Check what the function returns; often it returns a value where you expected it to return another function.

Is “int object is not callable” the same problem?

Yes: a name holding a number was called. Commonly sum = 0 followed by sum(values), or a method shadowed by an attribute as above.

Can a decorator cause this?

A decorator that forgets to return the wrapped function leaves the name bound to None, giving “NoneType object is not callable”. Make sure the decorator returns the wrapper.

Where to go next#

Fixing 'NameError: name is not defined'Read next

Keep reading

Keep going — pick your next guide

The fastest way to improve is to read one guide, then build the thing it describes. Start with the basics, or jump straight to a project.

Ask a question or share what worked

Your email address will not be published. Required fields are marked *