1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| def decorate(func, finery): def wrap(*args, **kwargs): return '{0} {1}'.format(finery, func(*args, **kwargs)) return wrap
def big_trouser(func): return decorate(func, "垮裤")
def tsherts(func): return decorate(func, "大T恤")
def sneaker(func): return decorate(func, "破球鞋")
def suit(func): return decorate(func, "西装")
def tie(func): return decorate(func, "领带")
def leather_shoes(func): return decorate(func, "皮鞋")
class Main: def __init__(self, name): self.name = name
@big_trouser @tsherts def one(self): print('第一种装扮') return self.show()
@leather_shoes @tie @suit def two(self): print('第二种装扮') return self.show()
@sneaker @leather_shoes @big_trouser @tie def three(self): print('第三种装扮') return self.show()
def show(self): return '装扮的{0}'.format(self.name)
if __name__ == '__main__': xc = Main('小菜') print(xc.one()) print(xc.two()) print(xc.three())
|