1

I'm baffled as to why the command line isn't able to run a certain script when the Python GUI can. What i'm trying to run is:

import random
print random.random()

Which runs fine in the Python GUI but when saved as a file (random.py) and ran through the command line

C:\Users\Name>python c:\Python\random.py

it produces this error:

TypeError: 'module' object is not callable

Has anyone had this problem or know why it occurs?

Thanks for your time!

1 Answer 1

8

This is because you have overridden the actual module random by creating your own random.py. Now, you're importing your own file which you're trying to call, and not actually importing the module which has the random function.

To fix this you need to do two things:

  1. Rename your file to something other than random.py

  2. Get rid of the .pyc created as a result of importing.

Sign up to request clarification or add additional context in comments.

1 Comment

All fixed. Thanks for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.