Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed10.multikabel.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'handler': 0.04; 'exception.': 0.09; 'exceptions': 0.09; 'exception': 0.12; 'attributes).': 0.16; 'propagate': 0.16; 'received:192.168.200': 0.16; 'subject:variable': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'worse,': 0.16; 'cc:addr:python-list': 0.16; 'mon,': 0.16; 'wrote:': 0.18; 'cc:no real name:2**0': 0.20; 'subject:list': 0.21; 'dec': 0.22; 'header:In-Reply-To:1': 0.22; '+0100,': 0.23; 'cc:2**0': 0.24; '(in': 0.26; "i'm": 0.26; 'print': 0.29; 'cc:addr:python.org': 0.29; 'second': 0.29; 'error': 0.29; 'example': 0.29; 'useless': 0.30; 'subject:?': 0.31; 'words,': 0.32; 'error.': 0.32; 'header:User-Agent:1': 0.33; 'try:': 0.34; 'except': 0.37; 'received:192': 0.37; 'using': 0.38; 'steven': 0.38; 'received:192.168': 0.40; '2011': 0.61; 'your': 0.61; 'header:Received:6': 0.61; 'received:62': 0.70; '"an': 0.84; 'exc:': 0.84 X-IronPort-AV: E=Sophos;i="4.71,304,1320620400"; d="scan'208";a="29528" X-Virus-Scanned: amavisd-new at zimbra.sequans.com Date: Tue, 06 Dec 2011 11:38:07 +0100 From: Jean-Michel Pichavant User-Agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100328) MIME-Version: 1.0 To: Steven D'Aprano Subject: Re: Scope of variable inside list comprehensions? References: <25531460.861.1323104692320.JavaMail.geo-discussion-forums@yqiv14> <4edd471a$0$29988$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <4edd471a$0$29988$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1323167890 news.xs4all.nl 6969 [2001:888:2000:d::a6]:54200 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:16716 Steven D'Aprano wrote: > On Mon, 05 Dec 2011 19:57:15 +0100, Jean-Michel Pichavant wrote: > > >> The proper way to propagate information with exceptions is using the >> exception itself: >> >> try: >> songs = [Song(_id) for _id in song_ids] >> except Song.DoesNotExist, exc: >> print exc >> > > > I'm not entirely sure that this is the proper way to propagate the > exception. I see far to many people catching exceptions to print them, or > worse, to print a generic, useless message like "an error occurred". > [snip] You misread me, I was referering to passing *information* with exception (in other words, use the exception attributes). In the example I gave, the exception has the songId value responsible for raising the error. I totaly second your opinion on how poor the above handler is (hmm not sure about this grammar construct, it sounds like a Yoda sentence). JM