简体   繁体   中英

python sys.path implementation

today, I checked how sys.path got implemented by python. i found it points to sys.pi file(python 2.7.8 in windows). 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. 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. Initialized from the environment variable PYTHONPATH , plus an installation-dependent default.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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