Let's say that I have a python script a.py in /A/B/a.py, and it's in the PATH environment variable. The current working directory is /X/Y/, and it's the directory where I call the /A/B/a.py.
You can get the current working directory with:
os.getcwd()
>> os.getcwd()
/X/Y
>> os.path.dirname(os.path.realpath(__file__)) # cannot be called interactively
/A/B
>> sys.path[0]
/A/B
>> os.path.abspath(sys.argv[0])
/A/B/a.py
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