I am trying to write a decorator that gets a single arg, i.e
@Printer(1)
def f():
print 3
So, naively, I tried:
class Printer:
def __init__(self,num):
self.__num=num
def __call__(self,func):
def wrapped(*args,**kargs):
print self.__num
return func(*args,**kargs**)
return wrapped
This is ok, but it also works as a decorator receiving no args, i.e
@Printer
def a():
print 3
How can I prevent that?