Popular recipes by Joakim Pettersson http://code.activestate.com/recipes/users/4174760/2014-12-03T09:55:06-08:00ActiveState Code RecipesEasy attribute setting and pretty representation (Python) 2014-12-03T09:55:06-08:00Joakim Petterssonhttp://code.activestate.com/recipes/users/4174760/http://code.activestate.com/recipes/578973-easy-attribute-setting-and-pretty-representation/ <p style="color: grey"> Python recipe 578973 by <a href="/recipes/users/4174760/">Joakim Pettersson</a> (<a href="/recipes/tags/attributes/">attributes</a>, <a href="/recipes/tags/lazy/">lazy</a>, <a href="/recipes/tags/traits/">traits</a>). Revision 2. </p> <p>Mix in one or more of these classes to avoid those tedious lines of administrative code for setting attributes and getting useful representations. </p> <p>If you inherit HasInitableAttributes, your should be able to obj = eval(repr(obj)) without loosing data.</p> <p>enthought.traits.api.HasTraits seems to mix in well also.</p> Attributes as local variables inside a with clause (Python) 2010-08-25T16:42:13-07:00Joakim Petterssonhttp://code.activestate.com/recipes/users/4174760/http://code.activestate.com/recipes/577372-attributes-as-local-variables-inside-a-with-clause/ <p style="color: grey"> Python recipe 577372 by <a href="/recipes/users/4174760/">Joakim Pettersson</a> (<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/prototyping/">prototyping</a>, <a href="/recipes/tags/syntax/">syntax</a>). Revision 2. </p> <p>This recipe defines three context managers that make it easier to step in and out of different parameter sets (‘Attributes’), allows data inheritance on such data sets (‘Scope’) and lets remote interpreters behave likewise (‘Workspace’). Just use “with object:” and there you have all its attributes ready to use as local variables. Changes are committed back into the object on exit from the ‘with’ clause. </p>