importing os.path -- why does it work?

Ian Kelly ian.g.kelly at gmail.com
Mon Jan 12 07:00:45 CET 2015


On Sun, Jan 11, 2015 at 10:31 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> But bizarrely, you can import os.path this way!
>
> py> import os.path
> py> os.path
> <module 'posixpath' from '/usr/local/lib/python3.3/posixpath.py'>
> py> os.__package__
> ''
>
>
>
> By what wizardry does this work?

By the wizardry of adding an entry to sys.modules.

https://hg.python.org/cpython/file/8b3c609f3f73/Lib/os.py#l112



More information about the Python-list mailing list