[Tutor] Getting the directory the program is in

Christopher Arndt chris.arndt at web.de
Mon Dec 11 18:55:46 CET 2006

Jordan Greenberg schrieb:
> Slightly hackish and nasty, but seems to do the trick. Someone'll
> probably suggest a better way, this is just the first thing I could come
> up with:

No, IMHO it's perfectly normal and safe practice, though this gets the full
path name of the program. If you want the directory it is in, do this:

from os.path import abspath, dirname
import sys

app_dir = abspath(dirname(sys.argv[0]))

Of course you have to do this before you (or some other code in your program)
do anything siilar to os.chris('/somewhere/else').


More information about the Tutor mailing list