functools.partial
from operator import add
import functools
print add(1,2) #3
add1 = functools.partial(add,1)
print add1(10) #11
functools.update_wrapper
#-*- coding: gbk -*-
def thisIsliving(fun):
def living(*args, **kw):
return fun(*args, **kw) + '活著就是吃嘛咱士。'
return living
@thisIsliving
def whatIsLiving():
"什么是活著"
return '對(duì)啊涩笤,怎樣才算活著呢?'
print whatIsLiving()
print whatIsLiving.__doc__
print
from functools import update_wrapper
def thisIsliving(fun):
def living(*args, **kw):
return fun(*args, **kw) + '活著就是吃嘛姑食。'
return update_wrapper(living, fun)
@thisIsliving
def whatIsLiving():
"什么是活著"
return '對(duì)啊帘靡,怎樣才算活著呢?'
print whatIsLiving()
print whatIsLiving.__doc__
#output
對(duì)啊,怎樣才算活著呢双霍?活著就是吃嘛。
None
對(duì)啊批销,怎樣才算活著呢洒闸?活著就是吃嘛。
什么是活著
functools.wraps
#-*- coding: gbk -*-
from functools import wraps
def thisIsliving(fun):
@wraps(fun)
def living(*args, **kw):
return fun(*args, **kw) + '活著就是吃嘛风钻。'
return living
@thisIsliving
def whatIsLiving():
"什么是活著"
return '對(duì)啊顷蟀,怎樣才算活著呢?'
print whatIsLiving()
print whatIsLiving.__doc__
#output
對(duì)啊骡技,怎樣才算活著呢鸣个?活著就是吃嘛。什么是活著
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者