finding dir of main .py file
Shane Geiger
sgeiger at ncee.net
Tue Dec 11 12:47:29 EST 2007
Some usage of __file__ will always get what you want in various situations:
print __file__
print modulename.__file__
print os.getcwd() + "/" + __file__
Rick Dooling 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
>
--
Shane Geiger
IT Director
National Council on Economic Education
sgeiger at ncee.net | 402-438-8958 | http://www.ncee.net
Leading the Campaign for Economic and Financial Literacy
More information about the Python-list
mailing list