importing os.path -- why does it work?

Steven D'Aprano steve at pearwood.info
Mon Jan 12 02:21:10 EST 2015


On 2015年1月11日 23:00:45 -0700, Ian Kelly wrote:
> 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

/head-desk
It's always the simplest thing... 
Thanks.
-- 
Steve


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /