Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如果出现警告,如何停止程序_Python - Fatal编程技术网

Python 如果出现警告,如何停止程序

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():

我尝试使用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():*

警告是非致命错误。出了点问题,但程序可以继续

可以使用标准库模块或通过命令行处理它们,并传递标志
-Werror
。在程序上:

import warnings

with warnings.catch_warnings():
    warnings.simplefilter('error')
    function_raising_warning()