I have a decorator:
from functools import wraps
def d(f):
@wraps(f)
def wrapper(*args,**kwargs):
print \'Calling func\'
return f(*arg
I'll also propose my solution:
first, create another decorator:
class DecorateOnce(object):
def __init__(self,f):
self.__f=f
self.__called={} #save all functions that have been decorated
def __call__(self,toDecorate):
#get the distinct func name
funcName=toDecorate.__module__+toDecorate.func_name
if funcName in self.__called:
raise Exception('function already decorated by this decorator')
self.__called[funcName]=1
print funcName
return self.__f(toDecorate)
Now every decorator you decorate with this decorator, will restrict itself to decorate a func only once:
@DecorateOnce
def decorate(f):
def wrapper...