I would like to make a decorator which could be used with or without a parameter : Something like this :
class d(object):
def __init__(self,msg='my default message'):
self.msg=msg
def __call__(self,fn):
def newfn():
print self.msg
return fn()
return newfn
@d('This is working')
def hello():
print 'hello world !'
@d
def too_bad():
print 'does not work'
In my code, only the use of decorator with parameter is working : how to proceed to have both working (with and without parameter) ?