How to read the directory which the actively running python file islocated in?

Jeremy Sanders jeremy+complangpython at jeremysanders.net
Fri Dec 1 06:49:37 EST 2006


Michael Malinowski wrote:

> Nevermind, I got it using the sys.argv[0]

That doesn't always work, as on unix the path isn't prepended onto
sys.argv[0] necessarily.

import os.path
...
os.path.dirname(os.path.abspath(__file__))

may be better.

-- 
Jeremy Sanders
http://www.jeremysanders.net/



More information about the Python-list mailing list