Popular recipes tagged "classes" but not "inheritance"http://code.activestate.com/recipes/tags/classes-inheritance/popular/2017-04-20T23:34:50-07:00ActiveState Code RecipesImplementing class-based callbacks in Python (Python)
2017-04-20T23:34:50-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580788-implementing-class-based-callbacks-in-python/
<p style="color: grey">
Python
recipe 580788
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/callbacks/">callbacks</a>, <a href="/recipes/tags/classes/">classes</a>, <a href="/recipes/tags/functions/">functions</a>, <a href="/recipes/tags/methods/">methods</a>, <a href="/recipes/tags/objects/">objects</a>, <a href="/recipes/tags/programming/">programming</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>This is a follow-on to this recently posted recipe:</p>
<p>Implementing function-based callbacks in Python:
<a href="https://code.activestate.com/recipes/580787-implementing-function-based-callbacks-in-python/?in=user-4173351" rel="nofollow">https://code.activestate.com/recipes/580787-implementing-function-based-callbacks-in-python/?in=user-4173351</a></p>
<p>This new recipe shows how to create and use callbacks in Python, using classes with methods, instead of plain functions, as was done in the recipe linked above. All other points such as reasons and benefits for using callbacks, are more or less the same as mentioned in the previous recipe, except that class instances can carry state around, so to that extent, the two approaches are different.</p>
<p><a href="https://jugad2.blogspot.in/2017/04/python-callbacks-using-classes-and.html" rel="nofollow">https://jugad2.blogspot.in/2017/04/python-callbacks-using-classes-and.html</a></p>
Money Game (Python)
2014-12-22T23:38:38-08:00Lance Spencehttp://code.activestate.com/recipes/users/4191386/http://code.activestate.com/recipes/578988-money-game/
<p style="color: grey">
Python
recipe 578988
by <a href="/recipes/users/4191386/">Lance Spence</a>
(<a href="/recipes/tags/classes/">classes</a>, <a href="/recipes/tags/games/">games</a>).
</p>
<p>I created this simple program as a possible start to something larger while I continue to learn Python. It's a simple program that can be used to help young kids learn to count change in US currency.</p>
Tracking Child Classes (Python)
2012-05-30T10:00:21-07:00Evert van de Waalhttp://code.activestate.com/recipes/users/4182118/http://code.activestate.com/recipes/578137-tracking-child-classes/
<p style="color: grey">
Python
recipe 578137
by <a href="/recipes/users/4182118/">Evert van de Waal</a>
(<a href="/recipes/tags/child/">child</a>, <a href="/recipes/tags/classes/">classes</a>).
</p>
<p>This recipe allows a base class to keep track of the child classes that inherit from it using a metaclass.</p>
Simple Abstract "Constants" to Use When @abstractproperty is Overkill or Misleading (Python)
2011-08-12T23:35:45-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/577761-simple-abstract-constants-to-use-when-abstractprop/
<p style="color: grey">
Python
recipe 577761
by <a href="/recipes/users/4177816/">Eric Snow</a>
(<a href="/recipes/tags/attributes/">attributes</a>, <a href="/recipes/tags/classes/">classes</a>).
</p>
<p>Use these instead of abstract properties when you don't plan on the abstract attribute being implemented with a property. And you can still give your attribute a docstring!</p>
Calculate the MRO of a class (Python)
2011-06-11T08:31:09-07:00Steven D'Apranohttp://code.activestate.com/recipes/users/4172944/http://code.activestate.com/recipes/577748-calculate-the-mro-of-a-class/
<p style="color: grey">
Python
recipe 577748
by <a href="/recipes/users/4172944/">Steven D'Aprano</a>
(<a href="/recipes/tags/c3/">c3</a>, <a href="/recipes/tags/classes/">classes</a>, <a href="/recipes/tags/method/">method</a>, <a href="/recipes/tags/mro/">mro</a>, <a href="/recipes/tags/order/">order</a>, <a href="/recipes/tags/resolution/">resolution</a>).
</p>
<p>This function allows you to calculate the Method Resolution Order (MRO, or sometimes linearization) of a class or base classes. This is the so-called "C3" algorithm, as used by Python (new-style classes, from version 2.3 and higher). The MRO is the order of base classes that Python uses to search for methods and attributes. For single inheritance, the MRO is obvious and straight-forward and not very exciting, but for multiple inheritance it's not always obvious what the MRO should be.</p>
Turn a Function Into a Class (Python)
2011-10-05T18:38:43-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/577822-turn-a-function-into-a-class/
<p style="color: grey">
Python
recipe 577822
by <a href="/recipes/users/4177816/">Eric Snow</a>
(<a href="/recipes/tags/classes/">classes</a>, <a href="/recipes/tags/functions/">functions</a>).
</p>
<p>The only catch is that the function has to return locals() at the end. And it doesn't do the __prepare__ part of 3.x metaclasses.</p>
Make a Class's Name Available in its Definition Body (Python)
2011-08-04T21:38:40-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/577813-make-a-classs-name-available-in-its-definition-bod/
<p style="color: grey">
Python
recipe 577813
by <a href="/recipes/users/4177816/">Eric Snow</a>
(<a href="/recipes/tags/classes/">classes</a>).
</p>
<p>Since a class object is created <em>after</em> the body is executed, it can't be available to the class body. Even the name is unavailable, at least by default. However, you can use the <code>__prepare__()</code> method in a metaclass to stick it in there. This recipe is a simple demonstration of how.</p>
Trace decorator for debugging (Python)
2011-01-24T18:40:51-08:00Kevin L. Sitzehttp://code.activestate.com/recipes/users/4173535/http://code.activestate.com/recipes/577551-trace-decorator-for-debugging/
<p style="color: grey">
Python
recipe 577551
by <a href="/recipes/users/4173535/">Kevin L. Sitze</a>
(<a href="/recipes/tags/classes/">classes</a>, <a href="/recipes/tags/debug/">debug</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/decorators/">decorators</a>, <a href="/recipes/tags/functions/">functions</a>, <a href="/recipes/tags/inspection/">inspection</a>, <a href="/recipes/tags/modules/">modules</a>, <a href="/recipes/tags/trace/">trace</a>).
Revision 2.
</p>
<p>This package provides a decorator for tracing function and method calls in your applications. The tracing capabilities are managed through the logging package, and several mechanisms are provided for controlling the destination of the trace output.</p>
<p>It also provides functionality for adding decorators to existing classes or modules.</p>