[Tutor] Getting the directory the program is in

Andreas Kostyrka andreas at kostyrka.org
Wed Dec 13 01:10:55 CET 2006

* Laszlo Antal <lantal at tmail.com> [061212 18:12]:
> 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

What about using os.path.dirname and os.path.basename for this


More information about the Tutor mailing list