This code was inspired after several discussions on the forum, and I'm especially indebted to PyTony for all of his help with these aspects.
The motivation behind this code is quite simple. I wanted a robust, light and general way of storing CSV data that could be used over and over again and had to have the following properties:
The user sets fields and defaults values, and then field typecasting was automatically employed.
The data is stored in a regular, lightweight type (In this case a mutable namedtuple)
The data is managed by a custom dictionary object.
The MutableNamedTuple class is written by another author (http://code.activestate.com/recipes/500261/) via the factory function "recordtype" and can be used as if it were an official NamedTuple object. Lines 8-137 are this source code, and in practical use cases, one would usually save it in a separate module and import it.
The user merely has to change the stict_fields to whatever datatype is intended to be store. This variable implicitly stores types, so the user does not have to do it. Defaults can also be placed in this variable. Once set, a mutablenamedtuple will be generated, and from that, the program makes a subclass called Record, which is effectively a mutablenamedtuple with extra typchecking.
Record objects then behave similar to named tuples. They are exceedingly easy to interface to file I/O and sqlite modules(http://docs.python.org/library/collections.html#collections.namedtuple_).
The RecordManager class is a custom dictionary that is responsible for storing all Record objects. This class has builtin settings for stringency and typechecking in the records. Under stringent settings, the user can define one or several object types which the RecordManger will accept (for now, only Record objects keyed by strings are accepted). Under lax settings, any valid key value pair can be stored.
The lines 261-306 are test cases.
Again, I want to iterate the purpose of this program is for the user to rip it off, redfeine the static_fields variable, and then add any custom methods in the Record and Record manager classes that are useful to analysis.