I know I should know this, sorry, but: When my app starts it needs to load two data files. They're likely to be in the same directory as the app itself. (If not, I handle the exception and put up dialogs to go look for them.) But so far I haven't been able to make the app look for them in the directory where it started, itself. (os.getcwd() seems to return the Resources folder in the Contents of the app's own bundle. system.argv[] points to __init__.py. I'm working in Mac OS 10.3.6, as you can tell.)
What's the standard, or best, or easiest -- and reliably cross-platform! -- way to do this?
I know I should know this, sorry, but: When my app starts it needs to load two data files. They're likely to be in the same directory as the app itself. (If not, I handle the exception and put up dialogs to go look for them.) But so far I haven't been able to make the app look for them in the directory where it started, itself. (os.getcwd() seems to return the Resources folder in the Contents of the app's own bundle. system.argv points to __init__.py. I'm working in Mac OS 10.3.6, as you can tell.)
What's the standard, or best, or easiest -- and reliably cross-platform! -- way to do this?
There is a new class coming in the next release that will help with this. It is called wxStandardPaths and has methods for getting appropriate paths for things like static application data, user data, config files, etc. See:
I know I should know this, sorry, but: When my app starts it needs
to load two data files. They're likely to be in the same directory
as the app itself. (If not, I handle the exception and put up
dialogs to go look for them.) But so far I haven't been able to make
the app look for them in the directory where it started,
itself. (os.getcwd() seems to return the Resources folder in the
Contents of the app's own bundle. system.argv points to
__init__.py. I'm working in Mac OS 10.3.6, as you can tell.)
What's the standard, or best, or easiest -- and reliably
cross-platform! -- way to do this?
There is a new class coming in the next release that will help with
this. It is called wxStandardPaths and has methods for getting
appropriate paths for things like static application data, user data,
config files, etc. See:
Lets wxStandardPaths know about the real program installation prefix on
a Unix system. By default, the value returned by GetInstallPrefix is
used.
Although under Linux systems the program prefix may usually be
determined automatically, portable programs should call this
function. Usually the prefix is set during program configuration if
using GNU autotools and so it is enough to pass its value defined in
config.h to this function.
It has to rely on the wxWidgets installation and not on the wxPython
installation.
How would those go along with multiple version installs? I suppose that
due to the check of the wxWidgets version one might not have it
available or might have very different places depending on who set
things up (thinking about Linux: the distributor who created the
packages -- your packages, SuSE's packages, Mandrake's packages,
etc. can be in different places --, the person who installed from
sources, the user who has his own private installation on his $HOME,
etc.).
On the other hand, it will make a lot of things easier and would allow
me to use directories in an absolute form instead of relative to where
my app is
I know I should know this, sorry, but: When my app starts it needs to load two data files. They're likely to be in the same directory as the app itself. (If not, I handle the exception and put up dialogs to go look for them.) But so far I haven't been able to make the app look for them in the directory where it started, itself. (os.getcwd() seems to return the Resources folder in the Contents of the app's own bundle. system.argv points to __init__.py. I'm working in Mac OS 10.3.6, as you can tell.)
What's the standard, or best, or easiest -- and reliably cross-platform! -- way to do this?
import inspect
import os
def moduledir(x=None):
# if called with a module identifier as an argument (not a string, just the bare name),
# it finds the directory
# where that module lives, else it finds where this function ( moduledir ) is located
if x is None:
x=moduledir
y=os.path.abspath(inspect.getfile(x))
y1=os.path.split(y)
return y1[0]
Paul Probert
University of Wisconsin
···
--
o__ | Paul Probert
,>/'_ | Associate Scientist
(_)\(_) | The University of Wisconsin-Madison
> Dept. of Electrical and Computer Engineering
> B426 Engineering Hall
> 1415 Engineering Dr.
> Madison, WI 53706