How to find script's directory

Tuomas tuomas.vesterinen at pp.inet.fi
Sun Aug 19 13:39:44 EDT 2007


#!/usr/bin/python
# module show_my_path
# ...
import os
print 'os.path.abspath(__file__):', os.path.abspath(__file__)
# ...
# end of module

[tv at tux class]$ python
 >>> import show_my_path
os.path.abspath(__file__): /misc/proc/py/test/class/show_my_path.py
 >>>
[tv at tux class]$ python show_my_path.py
os.path.abspath(__file__): /misc/proc/py/test/class/show_my_path.py



More information about the Python-list mailing list