Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:not': 0.03; 'syntax': 0.04; 'attribute': 0.07; 'reason,': 0.07; 'attributes': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Why': 0.09; 'used.': 0.09; 'python': 0.11; 'identifier,': 0.16; 'identifiers': 0.16; 'identifiers,': 0.16; 'piotr': 0.16; 'rarely': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject: \n ': 0.16; 'subject:accessing': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'variable': 0.18; 'header:User-Agent:1': 0.23; "aren't": 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'along': 0.30; 'subject:with': 0.35; 'something': 0.35; 'but': 0.35; 'subject:?': 0.36; 'similar': 0.36; 'being': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'real': 0.63; 'needing': 0.65; 'skip:m 50': 0.68; 'subject:there': 0.68; 'literally.': 0.84; 'subject:being': 0.84; 'imagine': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ned Batchelder Subject: Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Date: Tue, 03 Dec 2013 12:38:21 -0500 References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 18.189.126.187 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 In-Reply-To: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1386092315 news.xs4all.nl 2976 [2001:888:2000:d::a6]:46687 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60955 On 12/3/13 12:14 PM, Piotr Dobrogost wrote: > Hi! > > I find global getattr() function awkward when reading code. > What is the reason there's no "natural" syntax allowing to access attributes with names not being valid Python identifiers in a similar way to other attributes? > Something along the line of my_object.'valid-attribute-name-but-not-valid-identifier'? > > > Regards, > Piotr Dobrogost > I don't know the real reason, but I imagine it would be that it would be very rarely used. It would need to be an attribute that isn't a valid identifier, and you know the attribute at the time you write the code. I can see scenarios for needing attributes that aren't identifiers, but in many of them you also need to access them through a variable rather than literally. --Ned.