
This TypeError module not callable means you are trying to “call” an entire Python file (a module) instead of the specific function inside that file.
It’s a simple import confusion.
โก Quick Fix: TypeError: ‘module’ object is not callable โ Python Import Dot Notation and Direct Function Import Fix
You called the module itself instead of the function inside it โ use dot notation or import the function directly.
import random from random import choice my_list = [1, 2, 3] # Fix 1 โ Dot notation: module.function() result = random.choice(my_list) # Fix 2 โ Direct import: use the function name alone result = choice(my_list)
This tells you exactly where your boundary is โ now read through the root causes below to find which one broke your code and fix it permanently.
The Cause
You imported the random module, but you want to use the choice function inside it.
Problem Code:
import random my_list = [1, 2, 3] # You are trying to call the 'random' module result = random(my_list) # CRASH! TypeError: 'module' object is not callable
The Fixes
You have two ways to fix this, depending on your import style.
Fix 1: Use Dot Notation (Recommended)
Access the function inside the module using a dot (.).
import random # Import the whole module my_list = [1, 2, 3] # Correct: Call the 'choice' function on the 'random' module result = random.choice(my_list)
This is the clearest and most common way to do it.
Fix 2: Import the Function Directly
You can use from ... import ... to import only the function you need.
from random import choice # Import only the 'choice' function my_list = [1, 2, 3] # Now 'choice' is available directly result = choice(my_list)
This also works, but be careful! If you import choice and also have a variable named choice, you will run into other problems.
What This Error Exposes About Python’s Module and Callable Protocol
TypeError: 'module' object is not callable is Python’s __call__ lookup hitting a module object instead of a function. When you write import random, Python loads the entire random module into the current namespace under the name random. That name points to a module object โ a container for functions, classes, and constants. Module objects implement no __call__ method, so random(my_list) finds the container, checks for __call__, finds nothing, and raises the error immediately.
The dot notation fix works by routing through __getattribute__ instead. random.choice navigates into the module’s namespace and retrieves the choice function object โ which does implement __call__. That two-step lookup is the standard Python import pattern and the one that most clearly signals intent to every developer reading the code.
The direct import pattern from random import choice binds the function object directly to the name choice in your local namespace, skipping the module lookup entirely. That makes call sites cleaner but introduces a name collision risk: if any variable in the same scope is later assigned the name choice, it shadows the imported function silently. For standard library modules with short, generic function names โ choice, copy, open, map โ dot notation is safer because the module name acts as a namespace prefix that makes collisions impossible. Reserve direct imports for functions with specific, descriptive names that are unlikely to conflict with your own variables.





