Python处理此类“别名”的基本机制是什么?
>>> import os.path
>>> os.path.__file__
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/posixpath.pyc'
答案 0 :(得分:6)
取自CPython 2.6上的os.py:
sys.modules['os.path'] = path
from os.path import (curdir, pardir, sep, pathsep, defpath, extsep, altsep,
devnull)
path
之前被定义为特定于平台的模块:
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:
# ...
答案 1 :(得分:0)
也许os使用import作为?
import posixpath as path