Newbie Alert: Help me store constants pythonically

Brendan spam4bsimons at yahoo.ca
Tue Nov 8 11:40:14 EST 2005


Thanks for all the suggestions everyone.

After a bit of googling on the c.l.p. group, I see that building config
files is one of those 'Everyone has a favourite way of doing it' types
of problems, with lots of reimplementations.  I should change the
thread topic to "Yet Another Config File Question"!

Based on my requirements (thanks again for helping me identify these),
my config file should:

a) store numbers, strings, bools, keyed dictionaries and un-keyed lists
b) store nested structures of the above
c) be language neutral, preferably well supported in other languages,
and editors
d) have a simple api in Python, preferably translating values to native
types
e) be validated when read

I've checked out ConfigParser, ConfigObj, Pickle, PyYaml and
gnossis.xml.serialize, and none meet all the above criteria (though
they're all neat).

So I've decide to use ...drumroll please.... plistlib (
http://svn.python.org/projects/python/trunk/Lib/plat-mac/plistlib.py ).
 Why plists?

- I've got a simple api (readPlist(pathOrFile), writePlist(rootObject,
pathOrFile) ) already installed with macPython
- I have a dirt simple plist editor for knocking out the hundreds of
config values I need (
http://homepage.mac.com/bwebster/plisteditpro.html )
- The file format is xml, which is well supported in all languages.
- Since plists are the standard approach on the mac (though they aren't
OS specific by definition), the XML schema is well documented
(http://developer.apple.com/documentation/Darwin/Reference/ManPages/man5/plist.5.html),
and shared with thousands of other apps, so I won't have to worry about
obsolescence.

So away I go.  If anyone can suggest reasons I should avoid this
approach, please let me know before I get too invested.  Otherwise,
this might be a reasonable avenue for standardizing Python. (I hope
that doesn't draw to many flames :)

Brendan.




More information about the Python-list mailing list