/home/bar/foo/test.py:
I am trying test.py to print /home/bar/foo irrespective of from where I run the script from:
import os
def foo():
print os.getcwd()
test run:
[/home/bar $] python /home/bar/foo/test.py # echoes /home/bar
[/tmp $] python /home/bar/foo/test.py # echoes /tmp
os.getcwd() not the function for the task. How can I get this done otherwise?
Try this:
import os.path
p = os.path.abspath(__file__)
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