[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] cross-platform prefs storage?



Jack Nutting wrote:
This is not strictly pygame-related, but since most pygame projects support multiple platforms to a certain degree, some of you have probably encountered this issue before...

What I'm thinking about is storage of small amounts of user-specific data, for example preferences for video settings and control settings, or storage of a high-score table. Under Unix you'd usually put everything in a ~/.myprogram file/dir, on Mac OS X you can either do that or use NSUserDefaults. I guess I have two questions:

- Where do Windows programs ususally store these things? The registry (blah)? A .ini file in the launch directory (double blah)?

- Has anyone written/seen a python wrapper for this type of prefs storage that will take account of the platform and do the right thing?

This seems like such a common need, it seems pointless to reinvent the wheel.
Windows would normally store these things in "C:\Documents and Settings\$USER\Application Data\$APP". One (totally untested) way to handle this would be something like:

import os

def config_file(app_name, file_name, mode)
"""Return a configuration file named file_name, in the correct
location for this platform."""

home_dir = os.path.expanduser('~')

if os.name == 'nt':
config_location = os.path.join(home_dir, 'Application Data',
app_name, file_name)
else:
config_location = os.path.join(home_dir, '.' + app_name,
file_name)

return file(config_location, mode)