Code snippet: dualmethod descriptor

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Feb 3 22:09:02 EST 2010


En Sat, 30 Jan 2010 03:06:18 -0300, Steven D'Aprano
<steve at remove-this-cybersource.com.au> escribió:

> class dualmethod(object):
>     """Descriptor implementing dualmethods (combination
>     class/instance method).
>
>     Returns a method which takes either an instance or a class as
>     the first argument. When called on an instance, the instance is
>     passed as the first argument. When called as a class, the class
>     itself is passed instead.

Seems useful!
Perhaps a better place to post it would be
<http://code.activestate.com/recipes/langs/python/>, at least it's easier
to search.

-- 
Gabriel Genellina




More information about the Python-list mailing list