finding dir of main .py file
Ron Provost
ron.longo at cox.net
Tue Dec 11 16:40:11 EST 2007
Thanks, didn't realize it would be quite so easy.
----- Original Message -----
From: "Matt Nordhoff" <mnordhoff at mattnordhoff.com>
To: "ron.longo" <longorh at npt.nuwc.navy.mil>
Cc: <python-list at python.org>
Sent: Tuesday, December 11, 2007 2:50 PM
Subject: Re: finding dir of main .py file
> ron.longo wrote:
>> Nope, maybe I'm not explaining myself well.
>>
>> When I do os.getenv('HOME') I get back None.
>>
>> According to the docs, 'HOME' is the user's home directory on some
>> platforms. Which is not what I want.
>>
>> What I want is the directory in which an application's main .py file
>> resides. That is, when I type: python MyApp.py, I want to know in which
>> directory does MyApp.py reside?
>
> Shane is right.
>
>>>> print __file__
>
>>>> print modulename.__file__
>
> Just call os.path.dirname() on __file__ to get the directory.
> --
> --
> http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list