Some examples show
sys.path.insert(0, "path/to/whatever")
and other examples show
sys.path.insert(1, "path/to/whatever").
But I could not find any information of regarding the effect of using 0 as opposed to 1 and vice versa, for the first input argument of the insert() function.
Where can I find official documentation regarding this?
Also what is the difference between the two?
sys. path is a built-in variable within the sys module. It contains a list of directories that the interpreter will search in for the required module. When a module(a module is a python file) is imported within a Python file, the interpreter first searches for the specified module among its built-in modules.
The sys. path. append() method is used to temporarily add a path and as such, that path would be valid for a session for example.
Clicking on the Environment Variables button on the bottom right. In the System variables section, selecting the Path variable and clicking on Edit. The next screen will show all the directories that are currently a part of the PATH variable. Clicking on New and entering Python's install directory.
sys.path
is a list
, and so, of course, supports all list
methods with their exact semantics.
But for sys.path
specifically, element 0 is the path containing the script, and so using index 1 causes Python to search that path first and then the inserted path, versus the other way around when inserted at index 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With