Why do I get a TypeError: 'module' object is not callable when trying to import the random module?
Question: I am using Python 2.6 and am trying to run a simple random number generator
program (random.py):

    
    
    import random
    
    for i in range(5):
    
        # random float: 0.0 <= number < 1.0
        print random.random(),
    
        # random float: 10 <= number < 20
        print random.uniform(10, 20),
    
        # random integer: 100 <= number <= 1000
        print random.randint(100, 1000),
    
        # random integer: even numbers in 100 <= number < 1000
        print random.randrange(100, 1000, 2)
    

I'm now receiving the following error:

    
    
    C:\Users\Developer\Documents\PythonDemo>python random.py
    Traceback (most recent call last):
      File "random.py", line 3, in <module>
        import random
      File "C:\Users\Developer\Documents\PythonDemo\random.py", line 8, in <module>
        print random.random(),
    TypeError: 'module' object is not callable
    
    C:\Users\Developer\Documents\PythonDemo>
    

I've looked at the Python docs and this version of Python supports random. Is
there something else I'm missing?


Answer: Name your file something else. In Python a script _is_ a module, whose name is
determined by the filename. So when you start out your file `random.py` with
`import random` you are creating a loop in the module structure.

