Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'warnings': 0.04; 'matched': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'url:html)': 0.16; 'thanks,': 0.17; 'module': 0.19; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'script': 0.25; 'second': 0.26; 'header:X-Complaints-To:1': 0.27; 'prints': 0.31; 'url:python': 0.33; 'url:org': 0.36; 'should': 0.36; 'filter': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'simple': 0.61; 'skip:w 30': 0.69 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: John Reid Subject: warnings filters for varying message Date: Fri, 28 Jun 2013 07:14:35 +0100 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: cpc6-dals15-2-0-cust115.hari.cable.virginmedia.com User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372400088 news.xs4all.nl 15953 [2001:888:2000:d::a6]:37881 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49362 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.