Is a python script aware of its stored location path? -
Is a python script aware of its stored location path? -
/home/bar/foo/test.py:
i trying test.py print /home/bar/foo irrespective of run 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 function task. how can done otherwise?
try this:
import os.path p = os.path.abspath(__file__) python
Comments
Post a Comment