[issue33547] Relative imports do not replace local variables

Nick Coghlan report at bugs.python.org
Fri May 25 09:55:24 EDT 2018


Nick Coghlan <ncoghlan at gmail.com> added the comment:

Not as a statement, but you can force it with importlib.import_module:

$ python3 -c "import pkg; pkg.submodule = 1; import importlib; importlib.import_module('.submodule', 'pkg'); print(pkg.submodule)"
pkg
pkg.submodule
<module 'pkg.submodule' from '/home/ncoghlan/devel/misc/_play/pkg/submodule.py'>

We're getting off-topic for the issue tracker now, though - it's more a Stack Overflow type usage question (and the preferred answer would be to eliminate whatever's causing the shadowing problem in the originating module).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33547>
_______________________________________


More information about the Python-bugs-list mailing list