Popular recipes by Luke Dickens http://code.activestate.com/recipes/users/4171344/2010-07-20T15:04:52-07:00ActiveState Code RecipesAuto-Initialisation with default attribute values (Python) 2010-07-20T15:04:52-07:00Luke Dickenshttp://code.activestate.com/recipes/users/4171344/http://code.activestate.com/recipes/577322-auto-initialisation-with-default-attribute-values/ <p style="color: grey"> Python recipe 577322 by <a href="/recipes/users/4171344/">Luke Dickens</a> . Revision 3. </p> <p>This is a class adapted from one that performs a similar task in the PyML libraries by Asa Ben-Hur et al (see: <a href="http://pyml.sourceforge.net/%29." rel="nofollow">http://pyml.sourceforge.net/).</a></p> <p>The intention is to speed up development time, by allowing managed attribute names (and their default values) to be specified in a dictionary belonging to each class (here called classinitials). This avoids rewriting the standard initialisation procedure many times over. </p> <p>Subclasses inherit all superclasses' managed attributes, including the defaults unless overridden. This is found in the property initials. The copy constructor copies all managed attributes.</p> <p>Finally, any named argument to the __init__ function, whose name appears in the managed attributes dictionary, overrides the class default.</p> <p>I welcome any comments, criticism or suggested improvements.</p>