sys.arg gives me the python script. For example 'python hello.py' returns hello.py for sys.arg. But I need to know where the hello.py is located in full path.
How can I do that with python?
import sys print(sys.path)
From the docs:
As initialized upon program startup, the first item of this list, sys.path, is the directory containing the script that was used to invoke the Python interpreter.
You can use
__file__, a variable that contains the full path to the module from which you access it. This doesn't necessarily have to end with the ".py" extension, but can also be ".pyc" (or
There is also documentation available on __file__.