Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'attribute': 0.07; 'expressions': 0.07; 'skip:` 10': 0.07; 'attributes': 0.09; 'at.': 0.16; 'bit.': 0.16; 'determines': 0.16; 'evaluates': 0.16; 'expression,': 0.16; 'expression.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; "object's": 0.16; 'object).': 0.16; 'sure.': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'feb': 0.22; '>>>': 0.22; 'example': 0.22; 'to:name:python- list@python.org': 0.22; 'earlier': 0.24; '15,': 0.26; 'references': 0.26; 'right.': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'rest': 0.29; 'chris': 0.29; 'possibility': 0.29; 'said,': 0.30; 'subject:list': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; "d'aprano": 0.31; 'steven': 0.31; 'another': 0.32; 'agree': 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'object,': 0.36; 'raising': 0.36; 'yield': 0.36; 'list': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'little': 0.38; 'bad': 0.39; 'itself': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'even': 0.60; 'expression': 0.60; 'most': 0.60; "you're": 0.61; "you've": 0.63; 'here': 0.66; 'wait,': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ki5Xhrg/skJLw0s72q++5dXA4utDfNfIL6uT+FaFTh4=; b=mZZCrjd+y1eTPXsB0vtRkVBu2jEuIXJ7nVm7BYO9WyrkPuZypLkmJz5kKZ5N26NxiL B5d1imAarFzlDNFuHbGhK+FBdJn4t6/t8bsy16DNbDatUACEEUMP7USSDXqGZPqUiycD y8YMXXU2ukF6+Rbu6NPWqGwqsoyiZjtbHb9O+JPjl40n9S8N31pOlSH385H4ZeEEqMBG tiaxMolwyocmHrvQKGZXUsUIvkJGQfKSnrtBLHiN671jD39nBmdi7fNUAhEE4TNlD0RL HUZzKa7xN3MeWPv1ZgKFH2NMvOBF9pq9cSGgHLgaEvHtKmZ+0XH12e3ydtLsQWb3i6gj FeaA== MIME-Version: 1.0 X-Received: by 10.68.201.10 with SMTP id jw10mr13906174pbc.25.1392447461037; Fri, 14 Feb 2014 22:57:41 -0800 (PST) In-Reply-To: <52ff0dc5$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <13208de8-0f85-4e60-b059-dc087c8fda41@googlegroups.com> <52fefccc$0$29973$c3e8da3$5496439d@news.astraweb.com> <52ff0dc5$0$29973$c3e8da3$5496439d@news.astraweb.com> Date: Sat, 15 Feb 2014 17:57:40 +1100 Subject: Re: Explanation of list reference From: Chris Angelico To: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392447892 news.xs4all.nl 2839 [2001:888:2000:d::a6]:52897 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66387 On Sat, Feb 15, 2014 at 5:48 PM, Steven D'Aprano wrote: > On Sat, 15 Feb 2014 17:07:17 +1100, Chris Angelico wrote: > >> On Sat, Feb 15, 2014 at 4:36 PM, Steven D'Aprano >> wrote: >>> References can be names like `mystring`, or list items `mylist[0]`, or >>> items in mappings `mydict["key"]`, or attributes `myobject.attr`, or >>> even expressions `x+y*(1-z)`. >> >> I agree with most of what you've said, but I'm not sure I like that last >> bit. The expression evaluates to an object, yes, but it's not itself a >> reference... is it? > > You may be right. I will have to think about it a little more. Or a lot > more. Ah wait, I got it: I chose a bad example for the expression. Here > is a better one: > > myobj.alist[12]["some key"].attribute > > I think it is fair to call that both an expression and a reference. Sure. If it helps, the part that's a reference is the ".attribute" at the end; the rest is an expression which determines what object's attribute you're looking at. Same with the earlier parts; the [12] is a form of reference (albeit one that requires another object). But yes, this is an expression, and it evaluates to a reference. In any case, your main point is still valid: each of those forms will yield a reference to something. (Aside from the possibility of raising KeyError. As an expression, it has to yield a reference to an object.) ChrisA