Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 834
cppython Avatar asked Apr 30 '26 00:04

cppython


1 Answers

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 .

like image 83
Alexander Avatar answered May 02 '26 14:05

Alexander



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!