class or instance method
Bruno Desthuilliers
bruno.42.desthuilliers at websiteburo.invalid
Wed Jun 17 06:39:47 EDT 2009
Paul Johnston a écrit :
> 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.
IIRC, there's something quite similar in formencode.
More information about the Python-list
mailing list