【发布时间】:2010-11-09 12:55:28
【问题描述】:
Python 中处理此类“别名”的底层机制是什么?
>>> import os.path
>>> os.path.__file__
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/posixpath.pyc'
【问题讨论】:
标签: python import path module alias
Python 中处理此类“别名”的底层机制是什么?
>>> import os.path
>>> os.path.__file__
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/posixpath.pyc'
【问题讨论】:
标签: python import path module alias
也许 os 使用 import as?
import posixpath as path
【讨论】:
取自 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:
# ...
【讨论】: