Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Reuse of existing module name

import random

print(random.random())
$ python examples/pitfalls/random.py
Traceback (most recent call last):
  File "examples/pitfalls/random.py", line 1, in <module>
    import random
  File ".../examples/pitfalls/random.py", line 3, in <module>
    print(random.random())
TypeError: 'module' object is not callable

  • Write an example to use random number and call your example number.py
  • Same with any other module name.
  • Lack of multi-level namespaces
  • Solution: user longer names. Maybe with project specific names.