473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Find the path of a running .py program


Hi All!

There was a thread here, more than a month ago. It was about finding the
path of a .py file. I suggested os.abspath(__file__). Others told that
sys.argv[0] is better. I was not sure why I did not like that solution.
Now I ran into the problem again, and I now I remember what is the
problem with that. For windows service applications, it does not work.
The running program will be pythonservice.exe. Usually we want to know
where the python program (.py sources) are. So, if you ever write a
windows service in Python, make sure that you os.chdir to the correct
directory before you do anything else.

Original thread:

http://groups.google.com/group/comp....63b5a8ab48b0a0

Here is a snippet that helped me to overcome the problem:

import sys,os
os.chdir(os.path.split(__file__)[0])
keywords: windows, service, startup directory, startup folder, path of a
..py program

I hope this comment will help others in the future.

Cheers,

Laszlo

Mar 12 '07 #1
0 989

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sebastian Wangnick | last post by:
Dear all, I try to build an executable from a python program which uses a package called astrolabe. I'm using the following keyword parameters to setup: packages=,...
4
by: Andreas Neudecker | last post by:
Hi. I know you can read the filename of a program as sys.argv. But what about modules? Is there a similar way to find out the file name of a module (called by some other module or program) from...
6
by: Peter Hansen | last post by:
Greetings. Im trying to write a program that can be run from the command line. If I want to search for example after a file with the ending .pdf, I should be able to write in the command line:...
1
by: Alex | last post by:
Hello, in my company, we have a diagnostic tool for hardware. Depending on the hardware projcet, a different project configuration is needed. The configuration file is written in XML and...
5
by: Tim Eliot | last post by:
Just wondering if anyone has hit the following issue and how you might have sorted it out. I am using the command: DoCmd.TransferText acExportMerge, , stDataSource, stFileName, True after...
5
by: sathya moorthy via .NET 247 | last post by:
(Type your message here) hi. i am doing a small application project in c#. can any one help me how to find the directory of the current running program. how to create the input box in c# program. ...
5
by: Tom Vogel | last post by:
Creating a subfolder within my ASP.NET application folder fails with the above error, but only at my hosting provider. The command: Directory.CreateDirectory(path) Path is set to...
9
by: veracon | last post by:
I'm pretty new at Python, so I have no idea how to do this: How do I find the name of the directory that contains the application currently being executed (e.g. if the file is /home/user/file.py, I...
5
by: Mike Krell | last post by:
I'm running into problems trying to override __str__ on the path class from Jason Orendorff's path module (http://www.jorendorff.com/articles/python/path/src/path.py). My first attempt to do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.