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


Groups > comp.lang.python > #16716

Re: Scope of variable inside list comprehensions?

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 <prvs=314331f24=jeanmichel@sequans.com>
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 <jeanmichel@sequans.com>
User-Agent Mozilla-Thunderbird 2.0.0.24 (X11/20100328)
MIME-Version 1.0
To Steven D'Aprano <steve+comp.lang.python@pearwood.info>
Subject Re: Scope of variable inside list comprehensions?
References <25531460.861.1323104692320.JavaMail.geo-discussion-forums@yqiv14> <mailman.3315.1323111443.27778.python-list@python.org> <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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3338.1323167890.27778.python-list@python.org> (permalink)
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

Show key headers only | View raw


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

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


Thread

Scope of variable inside list comprehensions? Roy Smith <roy@panix.com> - 2011-12-05 09:04 -0800
  Re: Scope of variable inside list comprehensions? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2011-12-05 20:04 +0200
  Re: Scope of variable inside list comprehensions? Peter Otten <__peter__@web.de> - 2011-12-05 19:10 +0100
  Re: Scope of variable inside list comprehensions? Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-12-05 19:57 +0100
    Re: Scope of variable inside list comprehensions? Roy Smith <roy@panix.com> - 2011-12-05 11:15 -0800
    Re: Scope of variable inside list comprehensions? Roy Smith <roy@panix.com> - 2011-12-05 11:15 -0800
      Re: Scope of variable inside list comprehensions? Terry Reedy <tjreedy@udel.edu> - 2011-12-05 15:22 -0500
        Re: Scope of variable inside list comprehensions? Roy Smith <roy@panix.com> - 2011-12-05 14:36 -0800
        Re: Scope of variable inside list comprehensions? Roy Smith <roy@panix.com> - 2011-12-05 14:36 -0800
          Re: Scope of variable inside list comprehensions? Terry Reedy <tjreedy@udel.edu> - 2011-12-05 21:23 -0500
    Re: Scope of variable inside list comprehensions? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-05 22:35 +0000
      Re: Scope of variable inside list comprehensions? Roy Smith <roy@panix.com> - 2011-12-05 14:57 -0800
        Re: Scope of variable inside list comprehensions? Chris Angelico <rosuav@gmail.com> - 2011-12-06 13:35 +1100
      Re: Scope of variable inside list comprehensions? Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-12-06 11:38 +0100
  Re: Scope of variable inside list comprehensions? Rainer Grimm <r.grimm@science-computing.de> - 2011-12-05 22:42 -0800
    Re: Scope of variable inside list comprehensions? 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-06 02:16 -0800

csiph-web