473,396 Members | 1,846 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,396 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 1850
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.