> 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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4