Warning Exceptions

After getting repeated warnings of a library’s deprecated built-in functions, I decided to find a way to stop these warnings from coming as they were becoming a nuisance. I scoured forums on the web and many tutorials to come up with solution to help people who are having the same issue of wanting to ignore warnings.

About Warnings

Here is a little bit of a background of warnings, for those of you wondering: warnings are similar to errors, except they aren’t fatal to your code. Warning can be helpful for learning which lines of code to start testing when doing TDD, or knowing what could possibly be an issue during deployment of your code. Unfortunately though, for some developers warnings can be a nuisance, as they flood your IDE’s shell.

Ignoring Warnings

The following will help you ignore warnings:

from sys import warnoptions #import "warnoptions" from the "sys" module
from warnings import simplefilter #import "simplefilter" from the "warnings" module

if not warnoptions:
    simplefilter("ignore") #set the filter to ignore all warnings
1 Like