[Tutor] Getting the directory the program is in

Jordan Greenberg greenbergj at wit.edu
Mon Dec 11 18:19:41 CET 2006


Toon Pieton wrote:
> Hey friedly users!
> 
> I was wondering: how can I get the directory the program is in? For example
> "C:\Python Programs\Calculator\".
> 
> Thanks in advance for reading,
> Toon Pieton
> 

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:


from os.path import abspath
from sys import argv

print abspath(argv[0])


More information about the Tutor mailing list