Discuss / Python / 交作业,空格和tap区分真是要死了

交作业,空格和tap区分真是要死了

Topic source

秒归

#1 Created at ... [Delete] [Delete and Lock User]
def log(text):
    def decorator(func=text):
        @functools.wraps(func)
        def wrapper(*args, **kw):
            if(callable(func) == 1):
                print('%s %s():' % (text, func.__name__))
            else:
                print('call %s()' % func.__name__)
            return func(*args, **kw)
        return wrapper
    return decorator


def fx1():
    print('begin call')
    @log('execute')
    def now():
        print('2015-3-25')
    now()
    print('end call')

def fx2():
    print('begin call')
    @log
    def now():
        print('2016-3-25')
    now()
    print('end call')

fx1()
fx2()

请问这里用callable判断func是什么意思?为什么能把text赋给func

Alpha_an

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

直接给text赋个默认值是不是更简单点


  • 1

Reply