我想在我的原始包中使用原始decorator(例如“mypackage”中的“with\u error\u handler”)并执行一些函数。 但它返回的函数对象或错误消息太给定的参数。你知道吗
在我的包中:
def with_error_handler(func):
import traceback
from functools import wraps
from decorator import decorator
@decorator
@wraps(func)
def error_handler(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
strError = traceback.format_exc() + __file__ + '(' + str(args) + str(kwargs) + ')'
print(strError)
return error_handler
我想执行下面的代码。你知道吗
import mypackage
@mypackage.with_error_handler
def divnum(num):
print(1/num)
@mypackage.with_error_handler
def divone():
print(1/1)
if __name__ == '__main__':
divnum(2)
divone()
这些结果在这里
>>>divnum(2)
・・・with_error_handler() takes 1 positional argument but 2 were given
>>>divone()
・・・<function __main__.divone>
为什么会发生这些错误? 如何修复?你知道吗
没有必要
from decorator import decorator
。做没关系。你知道吗
和预期的一样
相关问题 更多 >
编程相关推荐