finding dir of main .py file
Stefan Reichör
stefan at xsteve.at
Tue Dec 11 16:01:23 EST 2007
Shane Geiger <sgeiger at ncee.net> writes:
> 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.
>>>
The following two versions are working for me:
import os, sys
print os.path.abspath(os.path.dirname(sys.argv[0]))
print os.path.abspath(os.path.dirname(__file__))
Stefan.
--
Posted via a free Usenet account from http://www.teranews.com
More information about the Python-list
mailing list