puhua.net

View My GitHub Profile

12 July 2020

Python 装饰器

#!/usr/bin/python
# -*-coding:utf-8 -*-


def meiyan1(func):
    def kouhong(*args, **kwargs):
        print ('口红')
        func(*args, **kwargs)

    return kouhong


def meiyan2(func):
    def miaomei(*args, **kwargs):
        print ('描眉')
        func(*args, **kwargs)

    return miaomei


def meiyan3(func):
    def beautiful(*args, **kwargs):
        func(*args, **kwargs)
        print ('她是个美女')

    return beautiful


@meiyan1
def girl(name):
    print('女孩名字叫:%s' % (name))


girl('qiao')
print('\n')


@meiyan1
@meiyan2
def girl(name):
    print('女孩名字叫:%s' % (name))


girl('qiao')
print('\n')


@meiyan1
@meiyan2
@meiyan3
def girl(name):
    print('女孩名字叫:%s' % (name))


girl('qiao')
print('\n')