[Python-Dev] ConfigParser shootout, preliminary entry

Josiah Carlson jcarlson at uci.edu
Mon Oct 18 19:46:47 CEST 2004


> Attributes may be 'generic' (untyped) or 'typed', and are stored in
> the order they are declared in the class statement. The value provided
> in the definition above is the 'default value'. Simple attributes may
> also be provided, but won't be type checked or kept in the original
> order. To read the ini file, just do this:

I think the syntax looks good, but as per a thread in python-list, you
cannot discover the order of class variables by any solution (metaclass
or otherwise), due to the fact that they become part of the class
dictionary; which is arbitrarily unordered.

If ordering is important to a user, one could have an optional __order__
attribute that gives the list of items in-order.


> class WebServerIni(IniFile):
>     class server(IniSection):
>         socketPort = TypedAttribute(8080)
>         threadPool = TypedAttribute(10)
>     class staticContent(IniSection):
>         bitmaps = TypedAttribute('c:/work/bitmaps')
>     class session(IniSection):
>         storageType = TypedAttribute('ram')

One nice thing about your solution is that one could pull out
docstrings to provide per-section documentation in the INI file, though
per-item docstrings (like WebServerIni.session.storageType) would be a
bit more difficult.

 - Josiah



More information about the Python-Dev mailing list