How do you get rid of useless warnings?
Martin Geisler
mg at daimi.au.dk
Tue Oct 7 11:16:32 EDT 2008
Grant Edwards <grante at visi.com> writes:
> 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 keyword in
> Python 2.6
>
> And this:
>
> /usr/lib/python2.5/site-packages/scipy/linalg/__init__.py:32:
> DeprecationWarning: NumpyTest will be removed in the next release;
> please update your code to use nose or unittest
>
> And so on...
Take a look at the -W command line option to python. From the man page:
-W argument
Warning control. Python sometimes prints warning message to
sys.stderr. A typical warning message has the following form:
file:line: category: message. By default, each warning is
printed once for each source line where it occurs. This option
controls how often warnings are printed. Multiple -W options
may be given; when a warning matches more than one option, the
action for the last matching option is performed. Invalid -W
options are ignored (a warning message is printed about invalid
options when the first warning is issued). Warnings can also be
controlled from within a Python program using the warnings mod-
ule.
The simplest form of argument is one of the following action
strings (or a unique abbreviation): ignore to ignore all warn-
ings; default to explicitly request the default behavior (print-
ing each warning once per source line); all to print a warning
each time it occurs (this may generate many messages if a warn-
ing is triggered repeatedly for the same source line, such as
inside a loop); module to print each warning only only the first
time it occurs in each module; once to print each warning only
the first time it occurs in the program; or error to raise an
exception instead of printing a warning message.
The full form of argument is action:message:category:mod-
ule:line. Here, action is as explained above but only applies
to messages that match the remaining fields. Empty fields match
all values; trailing empty fields may be omitted. The message
field matches the start of the warning message printed; this
match is case-insensitive. The category field matches the warn-
ing category. This must be a class name; the match test whether
the actual warning category of the message is a subclass of the
specified warning category. The full class name must be given.
The module field matches the (fully-qualified) module name; this
match is case-sensitive. The line field matches the line num-
ber, where zero matches all line numbers and is thus equivalent
to an omitted line number.
--
Martin Geisler
VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multi-Party Computation) to Python. See: http://viff.dk/.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 202 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20081007/e5e9bf13/attachment-0001.sig>
More information about the Python-list
mailing list