[英]how make handy decorator in python?
assume this decorator code : 假定此装饰器代码:
def makeitalic(fn):
def wrapped():
return "<i>" + fn() + "</i>"
return wrapped
@makeitalic
def hello():
return "hello world"
print (hello())
<i>hello world</i>
I want to make this output handy by this code: 我想通过以下代码方便输出:
def makeitalic(fn):
def wrapped():
return "<i>" + fn() + "</i>"
return wrapped
def hello():
return "hello world"
hello()
'hello world'
makeitalic(hello)
<function makeitalic.<locals>.wrapped at 0x02C25AE0>
makeitalic(hello())
<function makeitalic.<locals>.wrapped at 0x02E902B8>
print(makeitalic(hello))
<function makeitalic.<locals>.wrapped at 0x02C25AE0>
but it just return obj. 但它只是返回obj。 is there any way to reach the first code output by this method ?
有什么办法可以通过这种方法到达第一个代码输出?
就在这里:
makeitalic(hello)()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.