Reputation: 5787
How do I access a module named x that I masked with a variable named x?
Upvotes: 0
Views: 759
Reputation: 96806
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
Upvotes: 1
Reputation: 319821
don't name your variable x
or use import ... as
style.
>>> sys = 2
>>> import sys as s
>>> s
<module 'sys' (built-in)>
>>> sys
2
Upvotes: 3