Popular recipes tagged "polymorphism"http://code.activestate.com/recipes/tags/polymorphism/popular/2010-09-21T06:08:48-07:00ActiveState Code RecipesDecorator for writing polymorphic functions (Python) 2010-09-21T06:08:48-07:00Baptiste Carvellohttp://code.activestate.com/recipes/users/4175002/http://code.activestate.com/recipes/577393-decorator-for-writing-polymorphic-functions/ <p style="color: grey"> Python recipe 577393 by <a href="/recipes/users/4175002/">Baptiste Carvello</a> (<a href="/recipes/tags/polymorphism/">polymorphism</a>, <a href="/recipes/tags/unicode/">unicode</a>). Revision 2. </p> <p>Python 3 makes a clean separation between unicode text strings (str) and byte strings (bytes). However, for some tasks (notably networking), it makes sense to apply the same process to str and bytes, usually relying on the byte string beeing encoded with an ASCII compatible encoding.</p> <p>In this context, a polymorphic function is one which will operate on unicode strings (str) or bytes objects (bytes) depending on the type of the arguments. The common difficulty is that string constants used in the function also have to be of the right type. This decorator helps by allowing to use a different set of constants depending on the type of the argument.</p> SuperFly: Separating class heirarchy from class definition. (Python) 2009-02-15T20:47:51-08:00Ted Skolnickhttp://code.activestate.com/recipes/users/4169200/http://code.activestate.com/recipes/576652-superfly-separating-class-heirarchy-from-class-def/ <p style="color: grey"> Python recipe 576652 by <a href="/recipes/users/4169200/">Ted Skolnick</a> (<a href="/recipes/tags/inheritance/">inheritance</a>, <a href="/recipes/tags/polymorphism/">polymorphism</a>). Revision 2. </p> <p>This is a recipe for defining class hierarchies outside of class definitions. This way you could at, runtime, decide what class should act as the parent of a given class. A class could sometimes have one parent, sometimes another.</p>