views:

99

answers:

2

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'
A: 

Perhaps os uses import as?

import posixpath as path
Spidey
+3  A: 

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:
# ...
Bastien Léonard