Juan Felipe Contreras
Juan Felipe Contreras

Reputation: 75

TypeError when importing a module

I am new to Python and I am learning about packages. I am trying to use the random module, but I get the TypeError: 'module' object is not callable error. My code is:

import random

for i in range(3):
    print(random.random())

Does anyone could tell me why this might be happening?

Regards

Upvotes: 0

Views: 985

Answers (1)

Jin Kim
Jin Kim

Reputation: 35

What is the name of your file? If you named your file random.py, your script will not run.

Why do I get a TypeError: 'module' object is not callable when trying to import the random module?

I just tested your exact same code in a test.py file and it works no problem.

Upvotes: 1

Related Questions