Discuss / Python / 2&3题作业

2&3题作业

Topic source

o0stanley0o

#1 Created at ... [Delete] [Delete and Lock User]

import functools

def log(text):

    if isinstance(text, str):   #===带参数,头尾加参数字符串===

        def decorator(func):

            @functools.wraps(func)

            def wrapper(*args, **kw):

                print('%s' % text)

                func(*args, **kw)

                print('%s' % text)

                return

            return wrapper

    else:                       #===不带参数,头尾加begin和end===

        @functools.wraps(text)

        def decorator(*args, **kw):

            print('begin call')

            text(*args, **kw)

            print('end call')

            return

        return decorator

    return decorator

================

问一下各位大佬,为什么我以代码形式提交格式就是乱的呢???(全部挤到一行去了……)


  • 1

Reply