0

If anyone has any ideas about the following I would greatly appreciate hearing them.

I am running Python 3.5 system wide.

The following code snippet works fine in WING IDE and IDLE but not on Pycharm or Sublime Text (ctrl-B):

import random

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

When running this code I get the following error from Pycharm and Sublime text.

TypeError: 'module' object is not callable.

When running on IDLE or Wing IDE it runs fine.

Does anyone have an idea why this might be?

Thanks in advance!

O. Jacobs

1 Answers1

1

You must have named your python file random.py. Never give your scripts names of Python modules.

My own example:

  File "random.py", line 3, in <module>
    print(random.random())
TypeError: 'module' object is not callable

When changing the file name to anything else it works.

>> 0.4965569646861653
   0.7890484407352913
   0.8309030495394171
   0.9914424515913656
   0.1300969413381483
   0.7237824406106478
   0.8794402140337879
   0.5996808008843322
   0.4227883972570269
   0.7600499657995177
DeepSpace
  • 78,697
  • 11
  • 109
  • 154