Domanda

I'm new to python, and I find that to see the import search paths, you have to import the sys module and than access the list of paths using sys.path, if this list is not available until I explicitly import the sys module, so how the interpreter figure out where this module resides. thanks for any explanation.

È stato utile?

Soluzione

The module search path always exists, even before you import the sys module. The sys module just makes it available for you.

It reflects the contents of the system variable $PYTHONPATH, or a system default, if you have not set that environment variable.

Altri suggerimenti

There is a default search path within the interpreter. (https://docs.python.org/2/install/#modifying-python-s-search-path )

A default value for the path is configured into the Python binary when the interpreter is built.

BTW, sys is built into the Python interpreter. (https://docs.python.org/2/tutorial/modules.html#standard-modules)

One particular module deserves some attention: sys, which is built into every Python interpreter.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top