在上一个例子里,其实我们已经创建了一个装饰器!现在我们修改下上一个装饰器,并编写一个稍微更有用点的程序:def a_new_decorator(a_func): def wrapTheFunction(): print("I am doing some boring work before ex ...
def hi(): return "hi yasoob!" def doSomethingBeforeHi(func): print("I am doing some boring work before executing hi()") print(func()) doSomethingBeforeHi(hi) #outputs:I am doing some boring work befor ...
其实并不需要在一个函数里去执行另一个函数,我们也可以将其作为输出返回出来:def hi(name="yasoob"): def greet(): return "now you are in the greet() function" def welcome(): return "now you are in the wel ...