Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'programmer': 0.03; 'subject:not': 0.03; 'syntax': 0.04; 'dynamically': 0.07; 'wednesday,': 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; 'variant': 0.09; 'attributes,': 0.16; 'dict': 0.16; 'efficiency.': 0.16; 'identifiers': 0.16; 'key/value': 0.16; 'neutral': 0.16; 'piotr': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject: \n ': 0.16; 'subject:accessing': 0.16; 'way;': 0.16; 'prevent': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'later': 0.20; 'proposed': 0.22; 'saying': 0.22; 'header:User-Agent:1': 0.23; 'right.': 0.26; 'header:X-Complaints-To:1': 0.27; 'generally': 0.29; 'tim': 0.29; "doesn't": 0.30; '(which': 0.31; 'too.': 0.31; 'chase': 0.31; 'idea,': 0.31; 'names.': 0.31; 'could': 0.34; 'problem': 0.35; 'subject:with': 0.35; 'december': 0.35; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'accessing': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'should': 0.36; 'effort': 0.37; 'loss': 0.38; 'to:addr:python- list': 0.38; 'little': 0.38; 'bad': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'new': 0.61; 'skip:n 10': 0.64; 'more': 0.64; 'between': 0.67; 'invalid': 0.68; 'subject:there': 0.68; 'theoretical': 0.74; 'subject:being': 0.84; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Neil Cerutti Subject: Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Date: Wed, 4 Dec 2013 21:41:49 +0000 (UTC) Organization: Norwich University References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: jackman.norwich.edu User-Agent: slrn/0.9.9p1/mm/ao (Win32) 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: 1386193334 news.xs4all.nl 2852 [2001:888:2000:d::a6]:33756 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:61052 On 2013-12-04, Piotr Dobrogost wrote: > On Wednesday, December 4, 2013 2:06:44 AM UTC+1, Tim Chase wrote: >> >> I think random832 is saying that the designed purpose of setattr() >> was to dynamically set attributes by name, so they could later be >> accessed the traditional way; not designed from the ground-up to >> support non-identifier names. But because of the getattr/setattr >> machinery (dict key/value pairs), it doesn't prevent you from having >> non-identifiers as names as long as you use only the getattr/setattr >> method of accessing them. > > Right. If there's already a way to have attributes with these > "non-standard" names (which is a good thing) At best its a neutral thing. You can use dict for the same purpose with very little effort and no(?) loss of efficiency. > then for uniformity with dot access to attributes with > "standard" names there should be a variant of dot access > allowing to access these "non-standard" named attributes, too. New syntax needs more than theoretical justifications; it needs persuasive use cases. Using invalid identifiers as attributes is generally a bad idea, not something to do commonly. Your proposed syntax leaves the distinction between valid and invalid identifiers a problem the programmer has to deal with. It doesn't unify access to attributes the way the getattr and setattr do. -- Neil Cerutti