How to stop the program if there is a warning

I am trying to use nltk to handle some words, but there is a warning. I will find out if there is a word " Nations" , the program will trigger a warning. I wonder if there is a way to stop the program after a warning is raised. Thanks you

warning:

*UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  if word[0].lower() not in stopwords.words():*
+4
source share
1 answer

Warning is a non-fatal error. Something is wrong, but the program may continue.

They can be processed with a standard library module warningsor through the command line, passing a flag -Werror. Programatically:

import warnings

with warnings.catch_warnings():
    warnings.simplefilter('error')
    function_raising_warning()
+5
source

Source: https://habr.com/ru/post/1538496/