python: class namespace for simple decorator function -
I am new to those who decorate in Python and are struggeling with a simple decorator, to check my state The problem is that I want to know about everything in the decorator function itself and the actual work is 'logic' (? )
class myClass (object) ): __int __ (self): self .__ isFoo = wrong self .__baz = 0 def doFoo (self): ... itself .__ isFoo = true def fooInit (self, funk): if not itself .__ isFoo: Self.doFoo () return func @property @fooInit df findbiz (self): return self.__baz
However, with this one, I get an error
myObj = myClass () myObj.getBaz ~~ & gt; TypeError: fooInit () Absolutely 2 arguments (1 given)
That makes me understand something, because it's just self.fooinit (self.getBaz) if I think the decorator correctly Am, or?
So now I'm a little lost, how can I define decorator in an easy way, does it even know other objects in the class namespace?
Aruisdante following suggestions I managed to do a proper decorator
def fooInit (func): def _wrapped (auto, * IRG, ** QWARG): If not, then self.defoo: self.fooInit () return function (self, * args, ** kwargs) back _wrapped
(defined in my class )
Comments
Post a Comment