Python: From X Import Y Changes Previous Import Result
I am trying to understand the package and module name shadowing rules in python and stumbled across a case where I do not understand why the results that I see make any sense. This
Solution 1:
Consider how you access submodules, you would write mypackage.argparse
to access the submodule of mypackage
.
Now consider how attribute lookup for modules work, it searches for the attribute in the modules global namespace.
Putting these two together, the only way to access submodules is by adding them to the packages global namespace, this is the intended behaviour.
Post a Comment for "Python: From X Import Y Changes Previous Import Result"