simple question about directories

I do need to keep the data files out where a user could edit them, not in the bundle. I don't want to fiddle with special locations for the data files; I won't be doing any kind of real installation, just giving out an archive file that unpacks into the two data files and the app. My goal is to let a user unpack it and double-click the app, and (in the normal case, if nothing's been moved) have it find the data files in its same directory and come up clean without dialogs. (And the user can scrap the whole thing without any elaborate uninstall.)

When I run my app from the terminal, while coding and debugging, data files in the same directory as my module files are loaded without any fuss. The problem comes when I build the app (with py2app). Then, when I do this

myname = sys.argv[0].split('/')[-1]
mybasedir = os.sep.join(sys.argv[0].split('/')[:-1])
print "I am %s and am located at %s" % (myname, mybasedir)

what I get is

I am __boot__.py and am located at /Users/cohar/Documents/Python/PyProse/dist/PyProse.app/Contents/Resources

-- which is not helpful for finding data files outside the application's own bundle. I don't see quite why it does this, and I'm not sure I can *count* on it doing this; if I could, I could just do an os.chdir() to go up two levels, and be pretty sure of finding what I need. But won't it be completely different in a Windows environment?

Charles Hartman
Professor of English, Poet in Residence
http://cherry.conncoll.edu/cohar
http://villex.blogspot.com

Charles Hartman <charles.hartman@conncoll.edu> writes:

<...>

myname = sys.argv[0].split('/')[-1]
mybasedir = os.sep.join(sys.argv[0].split('/')[:-1])
print "I am %s and am located at %s" % (myname, mybasedir)

what I get is

I am __boot__.py and am located at
/Users/cohar/Documents/Python/PyProse/dist/PyProse.app/Contents/Resources

Nice to see that it works :slight_smile: How did you "unpacked" the code? It is
the default place for your user or you had changed something?

-- which is not helpful for finding data files outside the
application's own bundle. I don't see quite why it does this, and I'm
not sure I can *count* on it doing this; if I could, I could just do
an os.chdir() to go up two levels, and be pretty sure of finding what
I need. But won't it be completely different in a Windows environment?

You have another choice: use wx.Platform to find where the code is being
run. If it's on a Windows (the result is "__WXMSW__", IIRC) then choose
files from, e.g., C:/YouApp/Data/ hardcoded, do the same for other
platforms (on unices the result is '__WXGTK__', usually).

Of course if you'll have installation instructions and the users choose
another directory the files will still be one level below the program or
in the same directory as it is, depending on your approach, and it is
their job to remember where they unpacked it.

You can even adopt both things: try finding files in the hardcoded
directory first and check the application's current directory if you
find nothing.

You'll have to have some work done if you want to make your users lifes
easier :slight_smile:

Charles Hartman
Professor of English, Poet in Residence

  ^^^^^^^^^^^^^^^^^^^^

I hope I haven't assassinated the language -- yet. :slight_smile: In my defense I
am not a native speaker :slight_smile:

http://cherry.conncoll.edu/cohar
http://villex.blogspot.com

Be seeing you,

ยทยทยท

--
Godoy. <godoy@ieee.org>