Popular recipes by Yakov Markovitch http://code.activestate.com/recipes/users/98083/2002-01-28T10:07:35-08:00ActiveState Code RecipesDelphi-like property class for Python 2.2 (Python)
2002-01-28T10:07:35-08:00Yakov Markovitchhttp://code.activestate.com/recipes/users/98083/http://code.activestate.com/recipes/110061-delphi-like-property-class-for-python-22/
<p style="color: grey">
Python
recipe 110061
by <a href="/recipes/users/98083/">Yakov Markovitch</a>
.
</p>
<p>"property", a very nice new Python 2.2 feature that allows to specify per-attribute access logic, has one drawback: it requires to specify attribute access functions (fget and/or fset) even if direct access to the attribute is needed (the case when f.i. only setting the attribute must be controlled but getting can be performed directly). There is an excellent solution for this problem in systems like Delphi or Borland C++ Builder: a programmer can specify the name of a member variable as a getter and/or setter of a property, in which case corresponding property access goes directly to that member variable.
Here is a proposed solution for Python:</p>
Fast sort the list of objects by object's attribute (Python)
2001-03-11T07:57:45-08:00Yakov Markovitchhttp://code.activestate.com/recipes/users/98083/http://code.activestate.com/recipes/52230-fast-sort-the-list-of-objects-by-objects-attribute/
<p style="color: grey">
Python
recipe 52230
by <a href="/recipes/users/98083/">Yakov Markovitch</a>
.
</p>
<p>Fast sorting the list of objects by object's attribute using the "Schwartzian transform". Since this recipe uses _only_ builtins and doesn't use explicit looping, this is quite fast. Besides, it doesn't use any Python 2.0-specific features (such as zip() or list comprehensions) so can be used for Python 1.5.2/1.6 as well.</p>