After struggling with this for a while I came up with
what method that ALWAYS works for me. I use some sort
of .INI configuration file in almost 100% of my programs
(particularly the ones that I "freeze" with py2exe). I
routinely put a parameter in that .INI file that is
something like:
[defaults]
installpath=<installer will update this line>
..
.. Followed by other .INI configuration parameters
..
Then I put a lines in my Inno Installer script that are
something like:
[INI]
;
; Set the paths in progfile.INI to point to where the
; program was installed
;
Filename: "{app}\progfile.ini"; Section: "defaults";
Key: "installpath"; String: "{app}" (all on 1 line)
This allows the user to install the application anywhere
they wish AND I have a foolproof way of finding my way
back to the program file's installation directory. May
not be as elegant as some other approaches but it is
easily understandable and seems to work 100% of the time.
Larry Bates
Syscon, Inc.
<David Morgenthaler> wrote in message
news:dq********************************@4ax.com...
In many of my scripts I've used the following idiom for accessing data
files placed nearby:
BASEDIR = os.path.dirname(__file__)
.
.
.
fp = file(os.path.join(BASEDIR,"somefile.txt"))
.
.
.
img = image.open(os.path.join(BASEDIR,"images","someimag e.jpg"))
This works well with my cohorts who place their work on different
drives, in different directories, etc.
However, when I use py2exe to make an executable, the name '__file__'
is not defined.
Can anyone recommend an idiom that will work with py2exe?
Thanks in advance,
Dave M.
P.S. -- We've also tried the idiom
BASEDIR = os.path.dirname(sys.argv[0])
but the result can be misleading, for example, if the script is
launched from a desktop shortcut.