Sridhar Ratnakumar
Sridhar Ratnakumar

Reputation: 85262

How does os.path map to posixpath.pyc and not os/path.py?

What is the underlying mechanism in Python that handles such "aliases"?

>>> import os.path
>>> os.path.__file__
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/posixpath.pyc'

Upvotes: 3

Views: 1434

Answers (2)

Bastien Léonard
Bastien Léonard

Reputation: 61693

Taken from os.py on CPython 2.6:

sys.modules['os.path'] = path
from os.path import (curdir, pardir, sep, pathsep, defpath, extsep, altsep,
    devnull)

path is defined earlier as the platform-specific module:

if 'posix' in _names:
    name = 'posix'
    linesep = '\n'
    from posix import *
    try:
        from posix import _exit
    except ImportError:
        pass
    import posixpath as path

    import posix
    __all__.extend(_get_exports_list(posix))
    del posix

elif 'nt' in _names:
# ...

Upvotes: 6

MoshiBin
MoshiBin

Reputation: 3196

Perhaps os uses import as?

import posixpath as path

Upvotes: 0

Related Questions