Answer the question
In order to leave comments, you need to log in
What is the order in which Python modules are loaded?
Such a situation: there are 2 files in the current directory - sys.py and test.py. Why is it that when I import sys in test.py , it imports the standard library and not my file, since the list of module search paths (sys.path) lists the current directory first?
Answer the question
In order to leave comments, you need to log in
The sys.path variable contains a list of strings with the names of the directories in which to search for modules. It is initialized from the value of the PYTHONPATH environment variable and the default built-in value. You can add a path:
import sys
sys.path.append(/home/my/lib/python)
You can use the built-in dir() function to find out the names defined in a module. It returns a sorted list of strings:
dir(sys)
Each module has its own namespace, which is the global scope for all the functions it defines. In order for the variables of this module not to conflict with other global names or other modules, you must use the prefix: _module_name_._variable_name_ .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question