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


Groups > comp.lang.python > #26332

Re: NameError vs AttributeError

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'raised': 0.07; 'try:': 0.07; 'errors,': 0.09; 'oh,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; 'tuple': 0.09; 'cases': 0.15; 'both.': 0.16; 'enough.': 0.16; 'indexerror:': 0.16; 'keyerror': 0.16; 'mapping,': 0.16; 'message- id:@dough.gmane.org': 0.16; 'pair,': 0.16; 'popping': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'true:': 0.16; 'wrote:': 0.17; 'mechanism': 0.17; 'jan': 0.18; '31,': 0.22; 'example': 0.23; 'pass': 0.25; 'header :In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'possibly': 0.27; 'replace': 0.27; 'header:X-Complaints-To:1': 0.28; 'chris': 0.28; 'class': 0.29; 'usually': 0.30; 'code': 0.31; 'url:python': 0.32; 'to:addr:python-list': 0.33; 'another': 0.33; 'done': 0.34; 'list': 0.35; 'sequence': 0.35; 'pm,': 0.35; 'continue': 0.35; 'there': 0.35; 'received:org': 0.36; 'except': 0.36; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'subject:: ': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'easily': 0.39; 'header:Received:5': 0.40; 'is.': 0.62; 'decided': 0.65; 'book.': 0.65; 'jul': 0.65; 'subject:skip:A 10': 0.75; 'received:fios.verizon.net': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: NameError vs AttributeError
Date Tue, 31 Jul 2012 20:14:01 -0400
References <u1pke9-a46.ln1@satorlaser.homedns.org> <jv9eo7$jit$1@dough.gmane.org> <CALvWhxv8ww08AW_+N7K=XLnqOAz6Bmtd80M8qAeb3r4RCCm-8Q@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1
In-Reply-To <CALvWhxv8ww08AW_+N7K=XLnqOAz6Bmtd80M8qAeb3r4RCCm-8Q@mail.gmail.com>
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.2801.1343780060.4697.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1343780060 news.xs4all.nl 6857 [2001:888:2000:d::a6]:45179
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:26332

Show key headers only | View raw


On 7/31/2012 4:49 PM, Chris Kaynor wrote:
> On Tue, Jul 31, 2012 at 1:21 PM, Terry Reedy <tjreedy@udel.edu
> <mailto:tjreedy@udel.edu>> wrote:
>
>     Another example: KeyError and IndexError are both subscript errors,
>     but there is no SubscriptError superclass, even though both work
>     thru the same mechanism -- __getitem__.  The reason is that there is
>     no need for one. In 'x[y]', x is usually intented to be either a
>     sequence or mapping, but not possibly both. In the rare cases when
>     one wants to catch both errors, one can easily enough. To continue
>     the example above, popping an empty list and empty set produce
>     IndexError and KeyError respectively:
>
>        try:
>          while True:
>            process(pop())
>        except (KeyError, IndexError):
>          pass  # empty collection means we are done
>
> There is a base type for KeyError and IndexError: LookupError.
>
> http://docs.python.org/library/exceptions.html#exception-hierarchy

Oh, so there is. Added in 1.5 strictly as a never-directly-raised base 
class for the above pair, now also directly raised in codecs.lookup. I 
have not decided if I want to replace the tuple in the code in my book.

-- 
Terry Jan Reedy


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


Thread

NameError vs AttributeError Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-07-31 12:36 +0200
  Re: NameError vs AttributeError Terry Reedy <tjreedy@udel.edu> - 2012-07-31 16:21 -0400
  Re: NameError vs AttributeError Terry Reedy <tjreedy@udel.edu> - 2012-07-31 20:14 -0400
  Re: NameError vs AttributeError Ethan Furman <ethan@stoneleaf.us> - 2012-08-01 08:53 -0700
  Re: NameError vs AttributeError Terry Reedy <tjreedy@udel.edu> - 2012-08-01 12:59 -0400

csiph-web