Steven D'Aprano <st...@remove-this-cybersource.com.au> writes: > On Thu, 04 Feb 2010 00:09:02 -0300, Gabriel Genellina wrote: > >> En Sat, 30 Jan 2010 03:06:18 -0300, Steven D'Aprano >> <st...@remove-this-cybersource.com.au> escribió: >> >>> class dualmethod(object): > [...] > >> 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. > > > > Thank you for the encouragement. The recipe is now posted: > > http://code.activestate.com/recipes/577030/
Oddly, in Python 3 you can achieve something a bit similar very simply: >>> class A: ... def foo(self=None): ... return "Instance" if self else "Class" ... >>> A.foo() 'Class' >>> a = A() >>> a.foo() 'Instance' It works in python 3 because unbound methods are plain functions. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list