[Pythonmac-SIG] Where to put data

Charles Hartman charles.hartman at conncoll.edu
Wed Dec 22 00:57:32 CET 2004


OK, all this makes sense. But I'm startled to see how incredibly gnarly 
it is to have any kind of data -- if you want to preserve changes in 
the data, say by having a dictionary grow from one program run to the 
next -- at least on more than one platform. Is this so uncommon a 
pattern for applications? Oh well.


Charles Hartman
"Creative paranoia means developing at least as thorough a We-system as 
a They-system." Pynchon, Gravity's Rainbow, p. 638.

On Dec 21, 2004, at 3:32 PM, Bob Ippolito wrote:

> 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
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 3041 bytes
Desc: not available
Url : http://mail.python.org/pipermail/pythonmac-sig/attachments/20041221/a588e89a/attachment.bin


More information about the Pythonmac-SIG mailing list