我找不到谁定义了'__path__',为什么'__path__'可以使用.
import os
import sys
import warnings
import ConfigParser # ConfigParser is not a virtualenv module, so we can use it to find the stdlib
dirname = os.path.dirname
distutils_path = os.path.join(os.path.dirname(ConfigParser.__file__), 'distutils')
if os.path.normpath(distutils_path) == os.path.dirname(os.path.normpath(__file__)):
warnings.warn(
"The virtualenv distutils package at %s appears to be in the same location as the system distutils?")
else:
__path__.insert(0, distutils_path)#who defined me.???
exec open(os.path.join(distutils_path, '__init__.py')).read()
Run Code Online (Sandbox Code Playgroud)
您真的需要阅读一些Python文档并学习该语言的基础知识.
我查了一下,你好像说中文.以下是中文的Python文档资源:
http://www6.uniovi.es/python/doc/NonEnglish.html#chinese
现在,回答你的问题.我不确定答案是什么,所以我用谷歌.我在谷歌搜索" Python __path__"并很快发现:
http://docs.python.org/tutorial/modules.html
6.4.3.多个目录中的包
包支持另一个特殊属性
__path__.这被初始化为一个列表,其中包含在__init__.py执行该文件中的代码之前保存包的目录的名称.这个变量可以修改; 这样做会影响将来对包中包含的模块和子包的搜索.虽然通常不需要此功能,但它可用于扩展程序包中的模块集.