How do I access a module named x that I masked with a variable named x?
+1
A:
use sys.modules[module_name]
... and you should avoid masking module names: use wisely the import
statement e.g. import XYZ as ABC.
You can also rely on using a more complete namespace "path" e.g. os.path.xxx
jldupont
2010-03-01 11:07:30
But what if it's `sys` that's masked? Also, using a namespace path won't help if e.g. `os` is no longer a module.
Ignacio Vazquez-Abrams
2010-03-01 12:23:53
... and also if XYZ is masked and ... the point is: there are different ways to address the problem.
jldupont
2010-03-01 12:29:55
+4
A:
don't name your variable x
or use import ... as
style.
>>> sys = 2
>>> import sys as s
>>> s
<module 'sys' (built-in)>
>>> sys
2
SilentGhost
2010-03-01 11:07:58