Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #49362

warnings filters for varying message

From John Reid <j.reid@mail.cryst.bbk.ac.uk>
Subject warnings filters for varying message
Date 2013-06-28 07:14 +0100
Newsgroups comp.lang.python
Message-ID <mailman.3951.1372400088.3114.python-list@python.org> (permalink)

Show all headers | View raw


Looking at the docs for warnings.simplefilter
(http://docs.python.org/2/library/warnings.html) I think the following
script should only produce one warning at each line as any message is
matched by the simple filter

import warnings
warnings.simplefilter('default')
for i in xrange(2):
    warnings.warn('Warning message') # This prints 1 warning
    warnings.warn("Warning %d" % i)  # This prints 2 warnings

What do I need to do to get the warnings module just to print one
warning for the second warnings.warn line?

Thanks,
John.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

warnings filters for varying message John Reid <j.reid@mail.cryst.bbk.ac.uk> - 2013-06-28 07:14 +0100

csiph-web