class or instance method

Paul Johnston paul.paj at
Wed Jun 17 06:09:34 EDT 2009


I would like to have a method that is both a classmethod and an
instancemethod. So:

class MyClass(object):
  def myfunc(cls_or_self):

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.


More information about the Python-list mailing list