finding dir of main .py file

ron.longo longorh at npt.nuwc.navy.mil
Tue Dec 11 13:02:40 EST 2007


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?


Thanks,
Ron



Rick Dooling-2 wrote:
> 
> On Dec 11, 10:08 am, "ron.longo" <long... at npt.nuwc.navy.mil> wrote:
>> Is there any way that I can find the path of the main .py file of my
>> application?
>>
>> For example, I have an application with some resources which are in a
>> subdirectory:
>>
>>      myPythonApp.py
>>      /resources
>>          image1
>>          image2
>>          etc.
> 
> I just put the reference in my module. Don't hard code an absolute
> path, use the environment tools.
> 
> app_path = os.getenv('HOME') + "/your_sub_dir"
> 
> resources_path = os.getenv('HOME') + "/your_sub_dir/resources"
> 
> If there's another way, someone else will jump in.
> 
> rd
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

-- 
View this message in context: http://www.nabble.com/finding-dir-of-main-.py-file-tp14277145p14279627.html
Sent from the Python - python-list mailing list archive at Nabble.com.




More information about the Python-list mailing list