0

The problem I had was that some weeks ago, I had created a file random.py.

As it turned out, this filename made every program crash that uses the random module / import random.

Is there a way to avoid this problem? Even if I chose unique filenames, someone else using the same code might run into trouble.

Thomas
  • 507
  • 5
  • 15
  • You appear to be using Python 2; you should switch to Python 3 if you can, where the default is now to use absolute imports (which were added to the language precisely to avoid this kind of shadowing). – chepner Oct 23 '21 at 18:05
  • @chepner This can happen in python 3 as well. Python will prefer a `random.py` that can be found on PYTHONPATH over the standard library module. Correct solution is still to use absolute imports, but have all your modules within a common parent package. eg `mypackage/random.py` – Dunes Oct 23 '21 at 19:57

0 Answers0