I'm creating an app that relies on a configuration file at launch. The file
will always exist in the app's installation directory, but I have no control
over where that might be.
Is there an OS-independent way that I can instruct the app to look in it's
home directory for startup files? Right now, I'm hard coding the path, which
won't work.
Thanks,
Jeff 12 1346
The following script demonstrates a method that should work for you. I
believe it is entirely cross-platform.
#! /usr/bin/python
import sys
import os
print os.path.abspath(os.path.dirname(sys.argv[0]))
On 2005-05-11, jeff elkins <je********@earthlink.net> wrote: I'm creating an app that relies on a configuration file at launch. The file will always exist in the app's installation directory,
That's the first decision you need to examine. If you want
work on Unix platforms, that's not where configuration files go.
If you're talking about Windows, then all bets are off and you
can ignore the rest of this post.
but I have no control over where that might be.
Exactly.
Is there an OS-independent way that I can instruct the app to look in it's home directory for startup files?
No. That's not even the right place to look under Unix. If
you want to do things the "right" way under Unix, you look in
places like
/etc/<appname>
/etc/<appname>/whatever
/usr/local/etc/<appname>
/usr/local/etc/<appname>/whatever
One of the above would be used for system-wide configuration
stuff.
$HOME/.<appname>rc
$HOME/.<appname>/whatever
One of the above would be used for user-specific configuration
Right now, I'm hard coding the path, which won't work.
--
Grant Edwards grante Yow! I am covered with
at pure vegetable oil and I am
visi.com writing a best seller!
On Wednesday 11 May 2005 04:32 pm, he********@gmail.com wrote: The following script demonstrates a method that should work for you. I believe it is entirely cross-platform.
#! /usr/bin/python
import sys import os
print os.path.abspath(os.path.dirname(sys.argv[0]))
Works perfectly, thanks much!
Jeff
On 2005-05-11, he********@gmail.com <he********@gmail.com> wrote: The following script demonstrates a method that should work for you. I believe it is entirely cross-platform.
#! /usr/bin/python
import sys import os
print os.path.abspath(os.path.dirname(sys.argv[0]))
That will probably work most of the time, but...
1) you're not gauranteed that argv[0] contains the application
path/filename.
2) the directory containing the executable is not where
configuration files are supposed to be stored under
Unix/Linux.
--
Grant Edwards grante Yow! hubub, hubub, HUBUB,
at hubub, hubub, hubub, HUBUB,
visi.com hubub, hubub, hubub.
On Wednesday 11 May 2005 04:44 pm, Grant Edwards wrote: On 2005-05-11, he********@gmail.com <he********@gmail.com> wrote: The following script demonstrates a method that should work for you. I believe it is entirely cross-platform.
#! /usr/bin/python
import sys import os
print os.path.abspath(os.path.dirname(sys.argv[0]))
That will probably work most of the time, but...
1) you're not gauranteed that argv[0] contains the application path/filename.
2) the directory containing the executable is not where configuration files are supposed to be stored under Unix/Linux.
Thanks Grant,
I live and develop in Linux, but unfortunately, 99.99% of the users of this
particular application (analysis of medical laboratory data) will be working
with Windows.
I'm totally new to Python (obvious,yes?) so how might argv[0] fail?
Jeff
jeff elkins wrote: On Wednesday 11 May 2005 04:44 pm, Grant Edwards wrote:
On 2005-05-11, he********@gmail.com <he********@gmail.com> wrote:
The following script demonstrates a method that should work for you. I believe it is entirely cross-platform.
#! /usr/bin/python
import sys import os
print os.path.abspath(os.path.dirname(sys.argv[0]))
That will probably work most of the time, but...
1) you're not gauranteed that argv[0] contains the application path/filename.
2) the directory containing the executable is not where configuration files are supposed to be stored under Unix/Linux.
Thanks Grant,
I live and develop in Linux, but unfortunately, 99.99% of the users of this particular application (analysis of medical laboratory data) will be working with Windows.
I'm totally new to Python (obvious,yes?) so how might argv[0] fail?
If I make a symbolic link to the executable script and run it using that
link, sys.argv[0] will give the filename of that link, not the real file
it points to.
--
Robert Kern rk***@ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
On Wednesday 11 May 2005 10:18 pm, Robert Kern wrote: jeff elkins wrote: On Wednesday 11 May 2005 04:44 pm, Grant Edwards wrote:On 2005-05-11, he********@gmail.com <he********@gmail.com> wrote: The following script demonstrates a method that should work for you. I believe it is entirely cross-platform.
#! /usr/bin/python
import sys import os
print os.path.abspath(os.path.dirname(sys.argv[0]))
That will probably work most of the time, but...
1) you're not gauranteed that argv[0] contains the application path/filename.
2) the directory containing the executable is not where configuration files are supposed to be stored under Unix/Linux.
Thanks Grant,
I live and develop in Linux, but unfortunately, 99.99% of the users of this particular application (analysis of medical laboratory data) will be working with Windows.
I'm totally new to Python (obvious,yes?) so how might argv[0] fail?
If I make a symbolic link to the executable script and run it using that link, sys.argv[0] will give the filename of that link, not the real file it points to.
Thanks. I just tested that and it does indeed fail.
Jeff
jeff elkins <je********@earthlink.net> writes: On Wednesday 11 May 2005 04:44 pm, Grant Edwards wrote: On 2005-05-11, he********@gmail.com <he********@gmail.com> wrote: > The following script demonstrates a method that should work for you. I > believe it is entirely cross-platform. > > #! /usr/bin/python > > import sys > import os > > print os.path.abspath(os.path.dirname(sys.argv[0]))
That will probably work most of the time, but...
1) you're not gauranteed that argv[0] contains the application path/filename.
2) the directory containing the executable is not where configuration files are supposed to be stored under Unix/Linux.
Thanks Grant,
I live and develop in Linux, but unfortunately, 99.99% of the users of this particular application (analysis of medical laboratory data) will be working with Windows.
Yes, but Windows these days supports multiple users. Are you sure that
you want to restrict your users to one configuration file per
installed version of the program?
I'm not sure Windows has a good solution to this problem. My
experiences with trying to share applications between users on Windows
haven't been very pleasant.
<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
On Thursday 12 May 2005 05:24 am, Mike Meyer wrote: jeff elkins <je********@earthlink.net> writes: On Wednesday 11 May 2005 04:44 pm, Grant Edwards wrote: On 2005-05-11, he********@gmail.com <he********@gmail.com> wrote: > The following script demonstrates a method that should work for you. I > believe it is entirely cross-platform. > > #! /usr/bin/python > > import sys > import os > > print os.path.abspath(os.path.dirname(sys.argv[0]))
That will probably work most of the time, but...
1) you're not gauranteed that argv[0] contains the application path/filename.
2) the directory containing the executable is not where configuration files are supposed to be stored under Unix/Linux.
Thanks Grant,
I live and develop in Linux, but unfortunately, 99.99% of the users of this particular application (analysis of medical laboratory data) will be working with Windows.
Yes, but Windows these days supports multiple users. Are you sure that you want to restrict your users to one configuration file per installed version of the program?
I'm not sure Windows has a good solution to this problem. My experiences with trying to share applications between users on Windows haven't been very pleasant.
<mike
With this particular app, a single config file per install is required. It
sets up parameters that may vary from laboratory to laboratory but never do
within a single lab.
However, it might be a good idea to check the environment and if running under
*nix store configuration (and data files, which I didn't mention) in a sane
manner. That would solve the symlink issue anyway...
Thanks for the feedback folks,
Jeff
On 2005-05-11, jeff elkins <je********@earthlink.net> wrote: I'm totally new to Python (obvious,yes?) so how might argv[0] fail?
argv[0] contains whatever is put there by the program that
exec'ed you, and can therefore contain just about anything (or
nothing). It may not contain a full path, and your program's
install directory may not be in your $PATH (it be executed by a
shortcut or symlink).
If you're controlling how the program is installed and started,
then you're probably safe.
--
Grant Edwards grante Yow! I guess it was all a
at DREAM... or an episode of
visi.com HAWAII FIVE-O...
On Thu, 12 May 2005 00:24:55 -0500, Mike Meyer <mw*@mired.org> declaimed
the following in comp.lang.python: Yes, but Windows these days supports multiple users. Are you sure that you want to restrict your users to one configuration file per installed version of the program?
Even worse -- I've got a few applications that won't even run
from a "user account" because XP "protects" the normal "program files"
install directory, and the application tries to open/update the
configuration files.
-- ================================================== ============ < wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG < wu******@dm.net | Bestiaria Support Staff < ================================================== ============ < Home Page: <http://www.dm.net/~wulfraed/> < Overflow Page: <http://wlfraed.home.netcom.com/> <
Grant Edwards <gr****@visi.com> writes: On 2005-05-11, jeff elkins <je********@earthlink.net> wrote:
I'm totally new to Python (obvious,yes?) so how might argv[0] fail?
argv[0] contains whatever is put there by the program that exec'ed you, and can therefore contain just about anything (or nothing). It may not contain a full path, and your program's install directory may not be in your $PATH (it be executed by a shortcut or symlink).
That's true for the C-level, i.e. main's argv. If you're only concerned
about CPython and the program is a script living in a file, then
sys.argv[0] is the filename the python interpreter itself used to read
the script. Hence it's a valid filename that refers to the script. It
may be a relative filename, of course, in which case it won't be correct
anymore if the program changes its working directory.
Bernhard
--
Intevation GmbH http://intevation.de/
Skencil http://skencil.org/
Thuban http://thuban.intevation.org/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Neil Benn |
last post by:
Hello,
I'm looking at a small app which would need a very quick
startup time for the Python interpreter. It doesn't do much (copying
and caching of files, no GUI) but I need the Python...
|
by: Andrew Wrigley |
last post by:
Hi
Is there any way to walk thru memory to find a variable that holds a
reference to a recordset that has been left open? (I use ADO for my
recordsets.)
The reason I want this info:
I am...
|
by: Douglas Buchanan |
last post by:
Buttons don't work if form is opened on startup
A2k
If 'frmMain' is set to open by default at startup none of the buttons
work.
If 'frmMain' is opened from the database window then all the...
|
by: David |
last post by:
Hi,
Would someone please mind showing me how to obtain the absolute
path to a folder that is created under the application folder at install
time.
ie. On my development machine the path is...
|
by: Larry |
last post by:
I have a Perl script using DBD::DB2, that runs during system startup on
a Solaris system. The script is working fine during startup on many
machines, except on one machine it fails complaining...
|
by: chinkuang |
last post by:
Hi Everyone:
I have a question here: I used a startup object to protect my
application - whenever PC starts up, I will check the setting of my
application like registry, program files and so on,...
|
by: e'kong.tse |
last post by:
Hi All,
I'm trying to use C# to open up an Excel file that has a bunch of
dependent files. Inside Excel, you can specify the startup files in
Tools->Options->General Tab. My excel file has a...
|
by: rdemyan via AccessMonster.com |
last post by:
I'm having a complicated linking problem. Before I get into the particulars,
I'd like to know how Access links to the back-end file at startup, AFTER I've
distributed my application to the client....
|
by: =?Utf-8?B?RVF1QWw=?= |
last post by:
Hi,
We have an application developed in VC2005 with mixed code, primarily C++
but using a C# dll for database access (DBUploader), the dll exposes a C++
interface. We are experiencing...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
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...
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
| |