class or instance method
Paul Johnston
paul.paj at gmail.com
Wed Jun 17 06:09:34 EDT 2009
Hi,
I would like to have a method that is both a classmethod and an
instancemethod. So:
class MyClass(object):
@class_or_instance
def myfunc(cls_or_self):
pass
The semantics I'd like are:
When you call MyClass.myfunc, it gets passed a class
When you call MyClass().myfunc, it gets passed an instance
I'm sure I've seen some code to do this somewhere, but I can't find it
now. Any help appreciated.
Paul
More information about the Python-list
mailing list