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


Groups > comp.lang.python > #26369

Re: NameError vs AttributeError

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
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; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'oh,': 0.09; 'received:184.172': 0.09; 'received:gator410.hostgator.com': 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; 'nameerror': 0.16; 'pair,': 0.16; 'popping': 0.16; 'received:69.93': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'reedy': 0.16; 'true:': 0.16; 'wrote:': 0.17; 'mechanism': 0.17; '>>>': 0.18; '31,': 0.22; 'stick': 0.22; "i'd": 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; 'chris': 0.28; 'class': 0.29; 'usually': 0.30; 'code': 0.31; 'url:python': 0.32; 'could': 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; '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; 'think': 0.40; 'is.': 0.62; 'decided': 0.65; 'book.': 0.65; 'jul': 0.65; 'subject:skip:A 10': 0.75; 'received:gateway14.websitewelcome.com': 0.91
Date Wed, 01 Aug 2012 08:53:40 -0700
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Thunderbird 1.5.0.10 (Windows/20070221)
MIME-Version 1.0
To python-list@python.org
Subject Re: NameError vs AttributeError
References <u1pke9-a46.ln1@satorlaser.homedns.org> <jv9eo7$jit$1@dough.gmane.org> <CALvWhxv8ww08AW_+N7K=XLnqOAz6Bmtd80M8qAeb3r4RCCm-8Q@mail.gmail.com> <jv9sce$lgm$1@dough.gmane.org>
In-Reply-To <jv9sce$lgm$1@dough.gmane.org>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - gator410.hostgator.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - stoneleaf.us
X-BWhitelist no
X-Source
X-Source-Args
X-Source-Dir
X-Source-Sender ([192.168.10.136]) [72.11.125.166]:3238
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 2
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ==
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.2836.1343838883.4697.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1343838883 news.xs4all.nl 6972 [2001:888:2000:d::a6]:59852
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:26369

Show key headers only | View raw


Terry Reedy wrote:
> On 7/31/2012 4:49 PM, Chris Kaynor wrote:
>> On Tue, Jul 31, 2012 at 1:21 PM, Terry Reedy 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.

I think I'd stick with the tuple -- LookupError could just as easily 
encompass NameError and AttributeError.

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