I noticed, when I launch python
REPL and do:
import sys
print(sys.path)
The first element of the list is an empty string. This only happens in the REPL.
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 directory of the script which python is executing is added to sys. path . On Windows, this is always the empty string, which tells python to use the full path where the script is located instead. The contents of PYTHONPATH environment variable, if set, is added to sys.
Python sys path append() The sys. path. append() is a built-in function of the sys module in Python that can be used with path variables to add a specific path for an interpreter to search.
sys.path[0]
is an entry created by the Python executable to refer to the directory of the script being run. If no script is being run, e.g. the REPL has been invoked directly, an empty entry representing the current directory is added.
the first item of this list, path[0]
, is the directory containing the script that was used to invoke the Python interpreter.
If the script directory is not available (e.g. if the interpreter is invoked interactively or if the script is read from standard input), path[0] is the empty string, which directs Python to search modules in the current directory first.
As per documentation here
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