Discuss / Python / callable() 函数用于检查一个对象是否是可调用的。如果返回True,object仍然可能调用失败;但如果返回False,调用对象ojbect绝对不会成功。

callable() 函数用于检查一个对象是否是可调用的。如果返回True,object仍然可能调用失败;但如果返回False,调用对象ojbect绝对不会成功。

Topic source

aughay

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

#!/usr/bin/python

#-- coding: utf-8 --

import functools
def log(text): def decorate(func): @functools.wraps(func) def wraps(args, **kw): def call(f): print('End call: %s' % func.name) return f print('Begin call: %s' % func.name) f=func(args, **kw) return call(f) return wraps return decorate(text) if callable(text) else decorate

@log('waite...') def hello(): print('Hello World!') return 'Done'

@log def ite(s,n): for x in range(n): print(x*x,end=',') print(s)

n=hello() ite(n,10)


  • 1

Reply