finding dir of main .py file
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. If i just do a call to os.getcwd() I get back the directory I was in when I typed 'python myPythonApp.py' which could be any directory. What I want is the directory that contains the file myPythonApp.py. Then I can use this directory to construct the path to the resources directory. (Actually, the app I'm writing has several subdirectories with stuff that it needs such as plugins, configuration files, workspaces, etc. Thanks for the help. Ron -- View this message in context: http://www.nabble.com/finding-dir-of-main-.py-file-tp14277145p14277145.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: finding dir of main .py file
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" <[EMAIL PROTECTED]> 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.
--
http://mail.python.org/mailman/listinfo/python-list
Python application distribution
I haven't figured out a way to do this but see no reason why it cannot be done. I have a decent size application written in 100% Python. I would like to distribute this application, but only the .pyc files. Since the .pyc's are just the compiled sources I figured it would work, but if I copy just the pyc's and my main app's py into a directory by themselves, I'm unable to execute. Why is this? At this point I'm not really keen on handing out the source files to my application, it feels unprofessional. Thanks, Ron -- View this message in context: http://www.nabble.com/Python-application-distribution-tp16993351p16993351.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
