473,387 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Removing a warnings filter?

Hallöchen!

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.

In particular, I want to transform one special form of warning in an
exception to keep track of it more easily. However, before leaving
my function I want to restore the old status.

How can this be achieved? Thank you!

Tschö,
Torsten.

--
Torsten Bronger, aquisgrana, europa vetus
Jul 19 '05 #1
2 1848
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 "warnings.py", 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,
Dave
Jul 19 '05 #2
Hallöchen!

Dave Benjamin <ra***@lackingtalent.com> writes:
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 "warnings.py", it appears that warning filters are
added to a list called "warnings.filters".


Thank you, I'll use it in my program. However, I don't like it very
much, because warnings.filters isn't mentioned in the reference, and
in other languages that I've used, internal features are not
guaranteed to work across different versions.

Tschö,
Torsten.

--
Torsten Bronger, aquisgrana, europa vetus
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: rob | last post by:
In Python 2.3, this code still prints a warning (when run as a script, not from the interpreter). How do I get rid of the warning? I'd like to do it without passing command line args to python. ...
12
by: Gary | last post by:
Hi! guys, I have a SQL agent job fails because it gets 10 warnings when it runs a stored procedure. These warnings are trivial and can be ignored. Can I make it ignore these warnings and...
12
by: Ole Noerskov | last post by:
The function below is supposed to remove all childnodes with a name that starts with "keywords" in "myform" in the window.opener. It works fine if there's one keyword node. But you have to run...
3
by: Rad | last post by:
I have a table . It has a nullable column called AccountNumber, which is of varchar type. The AccountNumber is alpha-numeric. I want to take data from this table and process it for my application....
2
by: chand | last post by:
Hi., In my api.py file 'g_opt_list' is defined globally g_opt_list =,,,,,,] when I run the py file, I am getting the Following Error SyntaxWarning: name 'g_opt_list' is used prior to global...
8
by: Charlie Zender | last post by:
Hi, First, this may be a GCC or Linux-specific problem, I'm not sure. I am unable to compile a large body of code with extremely pedantic compile time checks activate, so that warnings cause...
32
by: Stephen | last post by:
Is there a standard way to remove the warning that a C compiler might produce from the statement: if (a = b) {} I don't want to do: if ((a = b) != 0) {} Because my "a = b" is actually...
3
by: Heather | last post by:
Hi. I am trying to permanently clear the filter criteria from my form properties. In another thread, I read a recommendation that said to "open the form in design mode, set the filter property and...
7
by: Grant Edwards | last post by:
<rant> I'm getting awfully tired of constant warnings about what's going to happen at some point in the future. Warnings like this: ./surfplot.py:313: Warning: 'with' will become a reserved...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.