如果我使用 pylint(通过 sublimerlinter),我会收到以下警告消息:
W602 已弃用的引发异常的形式
这是我在代码中使用异常的方式:
if CONDITION == True:
raise ValueError, HELPING_EXPLANATION
最佳答案
像这样提出你的异常:
if CONDITION == True:
raise ValueError(HELPING_EXPLANATION)
来自 PEP 8 -- Style Guide for Python Code - Programming Recommendations :
When raising an exception, use raise
ValueError('message')
instead of the older formraise ValueError, 'message'
.The paren-using form is preferred because when the exception arguments are long or include string formatting, you don't need to use line continuation characters thanks to the containing parentheses. The older form will be removed in Python 3.
关于python - 如何修复 : W602 deprecated form of raising exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11991637/