Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:not': 0.03; 'attributes': 0.09; 'subject:Why': 0.09; 'variant': 0.09; 'python': 0.11; 'attributes,': 0.16; 'backwards': 0.16; 'minus': 0.16; 'piotr': 0.16; 'subject: \n ': 0.16; 'subject:accessing': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'wed,': 0.18; 'code,': 0.22; '(in': 0.22; 'print': 0.22; 'right.': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'dec': 0.30; 'message- id:@mail.gmail.com': 0.30; '(which': 0.31; 'too.': 0.31; 'prints': 0.31; 'class': 0.32; 'subject:with': 0.35; 'equal': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'right?': 0.36; 'subject:?': 0.36; 'should': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'new': 0.61; 'today': 0.64; 'subject:there': 0.68; 'subject:being': 0.84; 'proposal,': 0.91; '2013': 0.98 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:content-transfer-encoding; bh=av+RqZ+4hx6LSztY24NaUk2nHVRQT/SeMYga6gME5sE=; b=csKY5dWWoUFHoeFlnS87Wr76+CwDba7zL7xWzaTSP3G8qg8AgyvY2dFwzzXgHfWDbL yloHheb8ibazQWEOYXLOwNpuYjiFwh5wsqkZEyNnqCfbg8S4dXbx6kW6lvoBo2BYnKAf 46GL95EyhBqueOwYbJLIpVlqZY0ysdSNYbtnwwIlCdl/cOH3F18IOqbpyP2w8y/onfF5 Q6oQW++quPRpjsnQkUCcfVAuWblld8tdJwCtGCvPOa7R3bO1uqN+p1qjgetLW8HbNWCC bP62oVVBbGV131u9AmIOwa1gJytMmei+KsGHvplufXRSEe0StEzowgzn7xCbbCpvofhd rFtQ== MIME-Version: 1.0 X-Received: by 10.66.141.165 with SMTP id rp5mr84902806pab.90.1386190701846; Wed, 04 Dec 2013 12:58:21 -0800 (PST) In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Date: Wed, 4 Dec 2013 15:58:21 -0500 Subject: Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? From: Jerry Hill To: "python-list (General)" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1386190722 news.xs4all.nl 2901 [2001:888:2000:d::a6]:52283 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:61049 On Wed, Dec 4, 2013 at 3:35 PM, Piotr Dobrogost wrote: > Right. If there's already a way to have attributes with these "non-standa= rd" names (which is a good thing) then for uniformity with dot access to at= tributes with "standard" names there should be a variant of dot access allo= wing to access these "non-standard" named attributes, too. Given the follow code, what do you think should print? class My_Class(object): pass bar =3D 1 my_object =3D My_Class() setattr(my_object, 'foo', 10) setattr(my_object, 'bar', 100) setattr(my_object, 'foo-bar', 1000) print(my_object.foo-bar) Today (in python 3.3), it prints 9, because my_object.foo is 10, the local variable bar is equal to 1, and 10 minus 1 is 9.. Under your new proposal, it would print 1000, right? Is there any way for your proposal to be backwards compatible? --=20 Jerry