-1

In the below when applying the decorator i get an error as TypeError: rt() takes exactly 2 arguments (1 given) ,how to get over this. the same goes with function decorator also ,hIs it because of the parent class.How to resolve this.

class applyfilter(object):
    def __init__(self,f):
       self.f=f
    def __call__(self,*args):
       self.f(*args) 

or

def applyfilter(f):
    def rt1(*args):
        print f.__name__
        print args
        return f(*args)
    return rt1

 class T1(SuperClass):
     @applyfilter
     def rt(self,data):
        print "In function rt" 

t=T1()
t.rt(123)

TypeError: rt() takes exactly 2 arguments (1 given)
Neo
  • 133
  • 1
  • 11

1 Answers1

1

I think you want the * operator in your function call, like so:

def rt1(*args):
    print f.__name__
    print args
    return f(*args)

This way, the parameters to rt1 will be packed into args, and then unpacked in the call to f(*args).

Reference: What does ** (double star/asterisk) and * (star/asterisk) do for parameters?

Robᵩ
  • 163,533
  • 20
  • 239
  • 308