Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'output': 0.04; 'root': 0.04; 'string.': 0.04; 'false.': 0.07; 'python': 0.09; '2.3,': 0.09; 'defined.': 0.09; 'self.data': 0.09; 'subclass': 0.09; 'subject:using': 0.09; 'index': 0.13; ':-)': 0.13; 'dec': 0.15; 'cleaner': 0.16; 'pythonic': 0.16; 'string': 0.17; 'wrote:': 0.17; '2.2': 0.17; 'instance': 0.17; 'pointed': 0.17; 'string,': 0.17; 'versions': 0.20; 'meant': 0.21; 'branch': 0.23; 'nearly': 0.23; 'seems': 0.23; 'testing': 0.24; 'header:In- Reply-To:1': 0.25; 'embedded': 0.27; 'replace': 0.27; 'message- id:@mail.gmail.com': 0.27; 'second,': 0.29; 'statements': 0.29; 'steven': 0.29; 'succeed': 0.29; 'way?': 0.29; 'that.': 0.30; 'december': 0.32; 'running': 0.32; 'could': 0.32; '11,': 0.33; 'to:addr:python-list': 0.33; 'code:': 0.33; 'times.': 0.33; 'received:google.com': 0.34; 'self': 0.34; 'clear': 0.35; 'replaced': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'possible': 0.37; 'ok,': 0.37; 'being': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'several': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'your': 0.60; 'remove': 0.61; 'first': 0.61; 'back': 0.62; 'production': 0.63; 'more': 0.63; 'here': 0.65; 'offer': 0.65; 'stuck': 0.65; 'due': 0.66; 'construction': 0.72; 'dict,': 0.84; 'to:name:python': 0.84; 'old.': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=xc5TWCOvDehDnk49LltLrk+WMh8Fxo6fEc9hqi7IeVY=; b=teECytolhcyaajzdBSkB3EAXEG+Liqm7bMVTWdjd7ATDMdHD9eB9jBjixQfFOgM16v /beIDTuKU9/9gltAMuCwIhc5UZmvMZOC/wcI4IaW9t53vokxlzdslp069+o4ZSya2DmY M9D5VWj6AFebY0QazSjNgt1EfQhyHJUH8g5DIqp0KWsfp70VVmSWo4g6mIKM9nopiOeM EGmhZkFB0tMdB9Ot9vB1T7BoygHGJQuvkDxIEMea6ZdGk7kdazoOQq6Cu1VJHs05eL8O TRJeZaWDgKd8H564+foXhDImVZDnI8zX1StvZsc6ahlxN0WQvfOZGHQirHxE2BnKKd1q GnpQ== MIME-Version: 1.0 In-Reply-To: <201212111557.24851.dave@linkscape.net> References: <201212102248.50766.dave@cinege.com> <201212111557.24851.dave@linkscape.net> From: Ian Kelly Date: Tue, 11 Dec 2012 14:53:12 -0700 Subject: Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes To: Python Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1355262824 news.xs4all.nl 6881 [2001:888:2000:d::a6]:33233 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:34650 On Tue, Dec 11, 2012 at 1:57 PM, Dave Cinege wrote: > On Tuesday 11 December 2012 01:41:38 Ian Kelly wrote: >> Second, in __getitem__ you start a loop with "for i in >> range(len(l)):", and then you use i as an index into l several times. >> It would be cleaner and more Pythonic to do "for i, part in >> enumerate(l):", and then you can replace every occurrence of "l[i]" > > My python is still 'old school' due to being stuck on old versions for in > production embedded system python applications. Just out of curiosity, how old are we talking? enumerate was added in Python 2.3, which is nearly 10 years old. Prior to 2.2 I don't think it was even possible to subclass dict, which would make your Thesaurus implementation unusable, so are these systems running Python 2.2? >> It's not clear to me what the isinstance call here is meant to be >> testing for. > > It's used to determine if it's the root instance of the recursive string > because self.data, not self must be used to access that. Can you offer a better > way? > >> The prior statements require key to be a string. If key >> is a string, then by construction l[0] is also a string. So it seems >> to me that the isinstance check here will always be False. > > OK, try and remove it and then get back to me. :-) Okay. I replaced this code: if isinstance(l[0], (dict, Thesaurus)): a = self.data else: a = self with: a = self and then I ran the examples, and the output was unchanged. As Steven pointed out, I don't see how that first branch could succeed anyway, since self.data is never defined.