Decorating one method of a class C with another method of class C?

Chris Angelico rosuav at gmail.com
Fri Jun 6 20:20:33 EDT 2014


On Sat, Jun 7, 2014 at 10:14 AM, Dan Stromberg <drsalists at gmail.com> wrote:
> Is there a way of decorating method1 of class C using method2 of class C?
>
> It seems like there's a chicken-and-the-egg problem; the class doesn't
> seem to know what "self" is until later in execution so there's
> apparently no way to specify @self.method2 when def'ing method1.

Since decoration happens at class creation, and arguments like self
are available only when the method's actually called, no, there's no
way you can define the method with something using information that
doesn't exist yet and may change from one call to the next :)

What are you trying to do, exactly?

ChrisA



More information about the Python-list mailing list