D
David Morgenthaler
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","someimage.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.
files placed nearby:
BASEDIR = os.path.dirname(__file__)
..
..
..
fp = file(os.path.join(BASEDIR,"somefile.txt"))
..
..
..
img = image.open(os.path.join(BASEDIR,"images","someimage.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.