Path: csiph.com!usenet.pasdenom.info!news.albasani.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:not': 0.03; 'attribute': 0.07; 'string': 0.09; 'expression:': 0.09; 'literal': 0.09; 'subject:Why': 0.09; 'way:': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; "wouldn't": 0.14; '(code': 0.16; 'advantage.': 0.16; 'dictionary.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'identifiers': 0.16; 'magic': 0.16; 'notation': 0.16; 'subject: \n ': 0.16; 'subject:accessing': 0.16; 'underscores': 0.16; 'do,': 0.16; 'so.': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'restrictions': 0.19; 'work,': 0.20; 'cc:addr:python.org': 0.22; 'question': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'dec': 0.30; 'message- id:@mail.gmail.com': 0.30; 'asked': 0.31; 'gives': 0.31; 'another': 0.32; 'could': 0.34; 'subject:with': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'done,': 0.36; 'indexed': 0.36; 'subject:?': 0.36; 'should': 0.36; 'two': 0.37; 'pm,': 0.38; 'though,': 0.39; 'either': 0.39; 'even': 0.60; 'skip:m 50': 0.68; 'subject:there': 0.68; 'special': 0.74; 'golf': 0.84; 'subject:being': 0.84; 'rusi': 0.91; 'was:': 0.91; 'to:none': 0.92; '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:cc :content-type; bh=bE5Cnb/73hk44Yb1k2B1sphg96VpRZevx/6e6UvITlE=; b=IE0dUHkRMA5lxnuHdPK6mCjbdzCRXlWkaHKrhUEGXgUV1Zvr5In7DBxCdGIJjND0XY 04pk9BL6Ye0JD7zeCWV7IVfZCPqmUyCAWwW5R7IvYqRyfYR0k0POSSGRhfhSD/OTt58y lL4j5qrLycoWDZh3xTGxQl6KT35NJP8NvZBEJRY1ahz7GZqwFtmA2cKzEKmsHjv6UVEY RcJ0wi2swRYWc3ZK4mfJUJVzifpiOb6K12yLiLCCP0wgrLMAJ7YJA3G6NFBo22htUhTS PN9IRzex1GHfi94CR5SVwnIGm1vN6Kb4zcn7xwJc2b6/2BVHfqfNzqdgApWCH0OMryNn c2cA== MIME-Version: 1.0 X-Received: by 10.68.236.133 with SMTP id uu5mr16711076pbc.153.1386153194154; Wed, 04 Dec 2013 02:33:14 -0800 (PST) In-Reply-To: <549180f1-fb98-4b59-b92f-5beceb1a6fb5@googlegroups.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <080d6a56-588b-425f-8968-8f77bc330427@googlegroups.com> <549180f1-fb98-4b59-b92f-5beceb1a6fb5@googlegroups.com> Date: Wed, 4 Dec 2013 21:33:14 +1100 Subject: Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? From: Chris Angelico Cc: "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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1386153202 news.xs4all.nl 2909 [2001:888:2000:d::a6]:58904 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:61007 On Wed, Dec 4, 2013 at 9:09 PM, rusi wrote: > OP wants attribute identifiers like outer_fieldset-inner_fieldset-third_field. > Say I have a python expression: > obj.outer_fieldset-inner_fieldset-third_field I don't think so. What the OP asked for was: my_object.'valid-attribute-name-but-not-valid-identifier' Or describing it another way: A literal string instead of a token. This is conceivable, at least, but I don't think it gives any advantage over a dictionary. What you could do, though, is create a single object that can be indexed either with dot notation or as a dictionary. For that to work, there'd have to be some restrictions (eg no leading underscores - at very least, __token__ should be special still), but it wouldn't be hard to do - two magic methods and the job's done, I think; you might even be able to manage on one. (Code golf challenge, anyone?) Of course, there's still the question of whether that even is an advantage. ChrisA