Popular recipes by Nabil Stendardo http://code.activestate.com/recipes/users/4177507/2011-03-31T20:07:18-07:00ActiveState Code RecipesDynamically modifying class attributes at runtime (Python)
2011-03-31T20:07:18-07:00Nabil Stendardohttp://code.activestate.com/recipes/users/4177507/http://code.activestate.com/recipes/577628-dynamically-modifying-class-attributes-at-runtime/
<p style="color: grey">
Python
recipe 577628
by <a href="/recipes/users/4177507/">Nabil Stendardo</a>
(<a href="/recipes/tags/class/">class</a>, <a href="/recipes/tags/modification/">modification</a>, <a href="/recipes/tags/monkeypatching/">monkeypatching</a>, <a href="/recipes/tags/open/">open</a>).
</p>
<p>However considered bad programming, Ruby/JavaScript-like open classes (i.e. classes which can be modified at runtime) actually can be a programming pattern when developing plug-in architectures. And, guess what, Python has that functionality too. This code allows to add attributes (typically methods) to classes, even when already instantiated.</p>