Python 如果出现警告,如何停止程序
我尝试使用nltk进行一些文字处理,但有一个警告。我找到了“国家”这个词�”,程序将抛出警告。我想知道是否有任何方法可以在警告引发后停止该程序。多谢各位 警告:Python 如果出现警告,如何停止程序,python,Python,我尝试使用nltk进行一些文字处理,但有一个警告。我找到了“国家”这个词�”,程序将抛出警告。我想知道是否有任何方法可以在警告引发后停止该程序。多谢各位 警告: *UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal if word[0].lower() not in stopwords.words():
*UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
if word[0].lower() not in stopwords.words():*
警告是非致命错误。出了点问题,但程序可以继续 可以使用标准库模块或通过命令行处理它们,并传递标志
-Werror
。在程序上:
import warnings
with warnings.catch_warnings():
warnings.simplefilter('error')
function_raising_warning()