TypeError: 'str' object is not callable, what it means and how to fix it

Calling is the () operation. This error means the name being called currently holds a plain value (a string, an int, a list) instead of a function. The cause is an assignment somewhere earlier baptizing a variable with a function's name, or the function's name being reused for data. The message names the type the callable turned out to be, and like its mirror image (not subscriptable), it is debugged by finding where the name changed jobs.

What it looks like

str = "report"                # shadows the builtin str()
label = str(42)               # 'str' is now your string

Traceback (most recent call last):
  File "main.py", line 2, in <module>
TypeError: 'str' object is not callable

# fixed: never name variables after builtins or functions
text = "report"
label = str(42)

The fix, in order

  1. Print the name being called, and type() of it. The traceback's line shows the call; printing the object shows what it actually is now. In notebooks, restart the kernel as a diagnostic: stale state from earlier cells is a prime suspect.
  2. Search the file for an assignment to that name. str =, list =, sum =, input =, or a function parameter or loop variable with the same name. One such line anywhere earlier in the run rebinds the name for everything after it.
  3. Rename data variables so they cannot collide. Never name variables str, list, dict, id, type, sum, min, max, or the name of any function you call. text, items, total cost nothing and prevent this entire category.
  4. Separate () from []: items(0) calls a list (this error); items[0] indexes it. Code written hastily or ported from languages with different conventions swaps them; the fix is the matching bracket.
  5. Check method-versus-property confusion on objects. Calling something that is a property (obj.name()) or a plain attribute raises this too; the library's documentation shows whether the name is a method to call or a value to read.

If it still happens

If the shadow is nowhere in your file, it may arrive through a wildcard import (from x import *) that overwrote a builtin in your namespace, or through a module you imported whose top level rebinds names the file then uses. Listing the name's origin with a quick interactive session pins it down.

Common questions

Why did it work in a fresh file but not in my notebook? Notebooks keep one long-lived namespace across cells. A cell that once assigned the name keeps it assigned until the kernel restarts, so the error can depend on execution history rather than the visible code, which is why “restart and run all” is a real diagnostic here.

What's the difference between not callable and not subscriptable? They are mirror images of one confusion: () calls, [] indexes. Not callable means brackets-that-call were applied to data; not subscriptable means index brackets were applied to something without elements. Both mean the value is not the kind of thing the syntax assumed.

Related errors

TypeError: 'int' object is not subscriptable · TypeError: unsupported operand type(s) · NameError: name is not defined