跟进一个较早的线程,我的问题是如何使用这个表达式:fn(self,*args, **kwargs
并像这样以 oo 方式调用它这self.fn(...)
是我的总程序,其中失败的行被注释掉:
def formatHeader(fn):
def wrapped(*args, **kwargs):
print "here is args prior to extraction - {0}".format(args)
if len(args) > 1:
self,args = args # remove self from args
else:
self, args= args[0], ()
print("Here are the arguments after extraction: {0} {1}".format(self, args))
#return '<div class="page_header">' + self.fn(*args, **kwargs)+'</div>'
return '<div class="page_header">' + fn(self,*args, **kwargs)+'</div>'
return wrapped
class MyPage(object):
def __init__(self):
self.PageName = ''
def createPage(self):
pageHeader = self.createHeader()
return pageHeader
def addem(self, a, b):
return a + b
@formatHeader #<----- decorator
def createHeader(self):
return "Page Header " + self.PageName
obj = MyPage()
print obj.createHeader()