简体   繁体   English

python sys.path实现

[英]python sys.path implementation

today, I checked how sys.path got implemented by python. 今天,我检查了python如何实现sys.path。 i found it points to sys.pi file(python 2.7.8 in windows). 我发现它指向sys.pi文件(Windows中的python 2.7.8)。 see code 看代码

argv = []
__stdout__ = file(__file__)
__name__ = 'sysoverride'
__stderr__ = file(__file__)
dllhandle = 0
exitfunc = None
stdin = file(__file__)
modules = {}
last_type = None
stderr = file(__file__)
path = []
last_value = None
hexversion = 17105408

my question is how python can print out a list of python paths with path=[] statement. 我的问题是python如何使用path = []语句打印出一个python路径列表。 it is really confused me. 这让我很困惑。 Thanks 谢谢

According to the doc's 根据医生的说法

sys.path is a list of strings that specifies the search path for modules. sys.path是一个字符串列表,用于指定模块的搜索路径。 Initialized from the environment variable PYTHONPATH , plus an installation-dependent default. 从环境变量PYTHONPATH初始化 ,加上依赖于安装的默认值。

In addition to that , there is a site module wich is automatically imported during initialization wich appends site-specific paths and builtins to the module search path . 除此之外,还有一个站点模块,它在初始化期间自动导入 ,它将特定于站点的路径和内置函数附加到模块搜索路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM