[Tutor] Getting the directory the program is in

Laszlo Antal lantal at tmail.com
Tue Dec 12 18:11:44 CET 2006


Hi,

I use this:

# This is the file name this code is in
curfile = "findcurdir.py"
#__file__ gives everything so slice off the file name
curdir = __file__[:-len(curfile)]
print curdir
#will print the curdir the file is in
#even if this file(module) has been imported

I hope it helps


Laszlo Antal


More information about the Tutor mailing list