Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'raised': 0.07; 'try:': 0.07; 'errors,': 0.09; 'lookup': 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; 'enough.': 0.16; 'illustrates': 0.16; 'indexerror:': 0.16; 'keyerror': 0.16; 'message- id:@dough.gmane.org': 0.16; 'nameerror': 0.16; 'necessity.': 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; 'jan': 0.18; '>>>': 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; 'am,': 0.27; 'replace': 0.27; 'header:X-Complaints-To:1': 0.28; 'chris': 0.28; '>>>>': 0.29; 'class': 0.29; 'error': 0.30; 'code': 0.31; 'point': 0.31; 'url:python': 0.32; 'could': 0.32; 'to:addr:python-list': 0.33; 'done': 0.34; 'list': 0.35; 'pm,': 0.35; 'continue': 0.35; 'there': 0.35; 'received:org': 0.36; 'except': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'thank': 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; 'you.': 0.61; 'is.': 0.62; 'decided': 0.65; 'book.': 0.65; 'jul': 0.65; 'subject:skip:A 10': 0.75; 'furman': 0.84; 'received:fios.verizon.net': 0.84; 'ethan': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: NameError vs AttributeError Date: Wed, 01 Aug 2012 12:59:32 -0400 References: <50195104.108@stoneleaf.us> 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: <50195104.108@stoneleaf.us> 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: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1343840406 news.xs4all.nl 6979 [2001:888:2000:d::a6]:41246 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26371 On 8/1/2012 11:53 AM, Ethan Furman wrote: > 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: >>>> 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. Thank you. Having to remember exactly which lookup error is encompassed by LookupError illustrates my point about the cost of adding entities without necessity. It also illustrates the importance of carefull naming. SubscriptError might have been better. -- Terry Jan Reedy