main_print 函数的问题
Issue with main_print function
我正在尝试一个带有装饰器功能的简单 python 程序。奇怪的是程序只执行装饰器函数的打印语句,而不执行调用函数main_print?
decor.py
def decorator(some_func):
def wrapper():
print('execute wrapper function from the decorator function')
return wrapper
@decorator
def main_print():
print('executing main_print')
main_print()
输出显示:
$ python3 decor.py
print('execute wrapper function from the decorator function')
我认为你必须调用装饰器内部的函数,例如
decor.py
def decorator(some_func):
def wrapper():
print('execute wrapper function from the decorator function')
some_func() # call the passed function
return wrapper
@decorator
def main_print():
print('executing main_print')
main_print()
我正在尝试一个带有装饰器功能的简单 python 程序。奇怪的是程序只执行装饰器函数的打印语句,而不执行调用函数main_print?
decor.py
def decorator(some_func):
def wrapper():
print('execute wrapper function from the decorator function')
return wrapper
@decorator
def main_print():
print('executing main_print')
main_print()
输出显示:
$ python3 decor.py
print('execute wrapper function from the decorator function')
我认为你必须调用装饰器内部的函数,例如
decor.py
def decorator(some_func):
def wrapper():
print('execute wrapper function from the decorator function')
some_func() # call the passed function
return wrapper
@decorator
def main_print():
print('executing main_print')
main_print()