[Pythonmac-SIG] Where to put data
Bob Ippolito
bob at redivi.com
Tue Dec 21 21:32:34 CET 2004
On Dec 21, 2004, at 10:23 AM, Charles Hartman wrote:
> (I also posted this to wxusers because it's sort of cross-platform --
> sorry if you're seeing it again.)
>
> With an earlier app I wanted an external data file and everybody told
> me to make it internal to the program (the app's Resources, I guess)
> instead. I couldn't, then. Now with a new app I want to do just that,
> but I'm not sure *how* to do it!
>
> It's a file of data -- a Python dictionary object, after it's loaded
> into memory -- which will grow and change as the app is used; when the
> app terminates the data ought to be saved with it for next time. In
> this case I don't want users fiddling with it apart from the app.
>
> What is the right way to do this? (What's the easy way?) Is there a
> simple method that will work for both Mac and Windows (and Linux)?
The right way to do it is NOT to have this file inside your
application. You should *never* assume that you can write to your own
application bundle. You *should* have a way to create this file from
scratch (which may be a template file inside Resources, which is never
written to).
As others have said there are different places you should put this file
dependent on operating system..
On Mac OS X it should probably go in one of the "Application Support"
directories. It's common convention to only place plist formatted
files in the Preferences directory, so unless you're serializing this
dictionary as a plist, I suggest going with Application Support instead
of Preferences.
On other *nix, it would typically go into a ~/.yourapplication
directory.
And for Windows, somewhere in their home directory (at least on
NT-based Windows). Optionally, you could put it in the registry
instead, which may be a good idea, depending on how big it is expected
to get.
As far as writing to your own application goes, here's a short list of
why that's bad:
- Will not work from CD-ROM, compressed disk image, etc.
- Probably will not work multi-user
- Probably a bad idea if the application is on a network drive
- User may not have permissions to write to the application
- If you break it, you really broke it.
- It can look virus-like and be picked up as such (particularly on
Win32 if you're writing to the .exe file).
You should be able to trust the user not to fiddle with it apart from
the app. Especially if it's a pickle file. It will be pretty buried,
anyway.
-bob
More information about the Pythonmac-SIG
mailing list