Python sys.path implementation

Today I checked how sys.path got the python implementation. I found that it points to the sys.pi file (python 2.7.8 on 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 a list of python paths using the path = [] statement. it really confused me. Thanks to

+3


source to share


1 answer


According to doc

sys.path is a list of strings indicating the search path for modules. Initialized from the PYTHONPATH environment variable and also depends on the default setting.



In addition to this, there is a site module, which is automatically imported during initialization , which adds site-specific paths and inline functionality to the module's search path.

+2


source







All Articles