Removing a warnings filter?

Dave Benjamin ramen at
Sat Jun 4 02:22:57 CEST 2005

Torsten Bronger wrote:
> When I add a warning filter with warnings.filterwarnings, how can I
> get rid of it?  I've read about resetwarnings(), but it removes all
> filters, even those that I didn't install in a certain function.

I have never used this module, but judging by a quick glance of the 
source to "", it appears that warning filters are added to a 
list called "warnings.filters". They are added to the beginning of the 
list unless you pass a true value for the "append" parameter of 
"filterwarnings", in which case they are added to the end. The usual way 
to remove items from a list apply, ie.:

del warnings.filters[0] # if append was false
del warnings.filters[-1] # if append was true

Note that all of these operations modify module data, which could have 
implications in multithreaded programs. If your program is 
multithreaded, you may want to consider using locks.

Hope this helps,

More information about the Python-list mailing list