Re: importing os.path -- why does it work?

2015-01-11 Thread Steven D'Aprano
On Sun, 11 Jan 2015 23:00:45 -0700, Ian Kelly wrote: > On Sun, Jan 11, 2015 at 10:31 PM, Steven D'Aprano > wrote: >> But bizarrely, you can import os.path this way! >> >> py> import os.path >> py> os.path >> py> >> os.__package__ >> '' >> >> >> >> By what wizardry does this work? > > By the wiz

Re: importing os.path -- why does it work?

2015-01-11 Thread Ian Kelly
On Sun, Jan 11, 2015 at 10:31 PM, Steven D'Aprano wrote: > But bizarrely, you can import os.path this way! > > py> import os.path > py> os.path > > py> os.__package__ > '' > > > > By what wizardry does this work? By the wizardry of adding an entry to sys.modules. https://hg.python.org/cpython/f

importing os.path -- why does it work?

2015-01-11 Thread Steven D'Aprano
Using the `spam.eggs` syntax for modules only works if spam is a package and eggs is a sub-package or module. For example, this fails: py> import glob.fnmatch Traceback (most recent call last): File "", line 1516, in _find_and_load_unlocked AttributeError: 'module' object has no attribute '__