classmethod and instance method

Jean-Paul Calderone exarkun at divmod.com
Thu Feb 2 15:48:41 EST 2006


On 2 Feb 2006 12:08:43 -0800, andychambers2002 at yahoo.co.uk wrote:
>Hi,
>
>I'm trying to write a method that needs to know both the class name and
>the  instance details
>
>class A:
>
>    @classmethod
>    def meth(cls, self):
>        print cls
>        print self
>
>a = A()
>a.meth(a)
>
>The above code seems to work as intended.  Could the same effect be
>achieved using a second decorator in addition to the @classmethod.  I
>tried
>
>    def instancemethod(self):
>        return self.meth(self)
>
>    @instancemethod
>    @classmethod
>    def meth(cls, self):
>        #do stuff
>
>but it didn't work.  Any suggestions?

Hint: decorators usually return functions.  What does your decorator return?

Jean-Paul



More information about the Python-list mailing list