Popular recipes tagged "classes" but not "mixins" and "functions"http://code.activestate.com/recipes/tags/classes-mixins-functions/2014-12-22T23:38:38-08:00ActiveState Code RecipesMoney 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>
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>