New submission from Sriram Krishna <[email protected]>:
Suppose I have a file profile.py in the same directory as the file I am running
(say test.py)
Let the contents of the files be:
profile.py:
raise Exception
test.py:
import cProfile
now if I run test.py
$ python test.py
Traceback (most recent call last):
File "test.py", line 1, in <module>
import cProfile
File "/usr/lib/python3.7/cProfile.py", line 10, in <module>
import profile as _pyprofile
File "/home/username/profile.py", line 1, in <module>
raise Exception
Exception
The file profile.py in '/usr/lib/python3.7' should have been loaded. This would
also happen if test.py imported a module or package which imported cProfile.
The only possible way of avoiding this problem completely is by ensuring that
the name of any the python files don't match a builtin python file or the name
of any installed package.
A python user can't be expected to know the name of every possible file in the
Python standard library. Maybe the current working directory should be removed
from sys.path when importing from within another module not in the same
directory.
----------
components: Interpreter Core
messages: 330874
nosy: ksriram
priority: normal
severity: normal
status: open
title: name shadowing while a module tries to import another
type: behavior
versions: Python 3.7
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue35375>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com