Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:not': 0.03; 'received:134': 0.05; 'attribute': 0.07; 'wednesday,': 0.07; 'string': 0.09; 'expression:': 0.09; 'identifier': 0.09; 'parsed': 0.09; 'spaces': 0.09; 'subject:Why': 0.09; 'python': 0.11; "'+'": 0.16; "'-'": 0.16; 'all?': 0.16; 'attributes.': 0.16; 'identifier.': 0.16; 'identifiers': 0.16; 'letters.': 0.16; 'literal.': 0.16; 'minus': 0.16; 'operation.': 0.16; 'statement.': 0.16; 'stop?': 0.16; 'subject: \n ': 0.16; 'subject:accessing': 0.16; 'typeerror:': 0.16; 'language': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'import': 0.22; '(in': 0.22; 'proposed': 0.22; 'header:User- Agent:1': 0.23; 'string,': 0.24; 'decide': 0.24; 'second': 0.26; '(for': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'bigger': 0.30; 'characters': 0.30; 'dec': 0.30; 'designer': 0.30; "skip:' 10": 0.31; '"",': 0.31; 'file': 0.32; '(most': 0.33; 'problem': 0.35; 'subject:with': 0.35; 'agree': 0.35; 'december': 0.35; 'point.': 0.35; 'subject:?': 0.36; 'should': 0.36; 'being': 0.38; 'others.': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'anything': 0.39; 'recent': 0.39; 'does': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'remove': 0.60; 'above,': 0.60; 'ian': 0.60; 'first': 0.61; 'complete': 0.62; 'name': 0.63; 'choose': 0.64; 'more': 0.64; '(that': 0.65; 'world': 0.66; 'between': 0.67; 'subject:there': 0.68; 'limit': 0.70; 'qualified': 0.72; 'as:': 0.81; 'differently:': 0.84; 'pardon': 0.84; 'subject:being': 0.84; 'rusi': 0.91; '2013': 0.98 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ap8EANACn1KGuA9G/2dsb2JhbABauXWDBoE1gxkBAQV4EQsYCRYECwkDAgECAUUTCAKHfq9kin6GWheOEhQBXhaEHQOYFIYui2WBa4E/gWcBCBc Date: Wed, 04 Dec 2013 11:29:06 +0100 From: Antoon Pardon User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20131005 Icedove/17.0.9 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? 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> In-Reply-To: <549180f1-fb98-4b59-b92f-5beceb1a6fb5@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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: 57 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1386152954 news.xs4all.nl 2959 [2001:888:2000:d::a6]:55035 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:61006 Op 04-12-13 11:09, rusi schreef: > On Wednesday, December 4, 2013 2:27:28 PM UTC+5:30, Ian wrote: >> On Tue, Dec 3, 2013 at 11:31 PM, rusi wrote: >>> Its a more fundamental problem than that: >>> It emerges from the OP's second post) that he wants '-' in the attributes. >>> Is that all? >>> >>> Where does this syntax-enlargement stop? Spaces? Newlines? >> >> At non-strings. >> >>>>> setattr(foo, 21+21, 42) >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: attribute name must be string, not 'int' > > Not sure what's your point. > > OP wants attribute identifiers like outer_fieldset-inner_fieldset-third_field. > Say I have a python expression: > obj.outer_fieldset-inner_fieldset-third_field > > It can (in the proposed extension) be parsed as above, or as: > obj.outer_fieldset - inner_fieldset-third_field > the first hyphen being minus and the second being part of the identifier. > > How do we decide which '-' are valid identifier components -- hyphens > and which minus-signs? > > So to state my point differently: > The grammar of python is well-defined > It has a 'sub-grammar' of strings that is completely* free-for-all ie just > about anything can be put into a string literal. > The border between the orderly and the wild world are the quote-marks. > Remove that border and you get complete grammatical chaos. > [Maybe I should have qualified my reference to 'spaces'. > Algol-68 allowed spaces in identifiers (for readability!!) > The result was chaos] > > I used the spaces case to indicate the limit of chaos. Other characters (that > already have uses) are just as problematic. I don't agree with the latter. As it is now python can make the distinction between from A import B and fromAimportB. I see no a priori reason why this should be limited to letters. A language designer might choose to allow a bigger set of characters in identifiers like '-', '+' and others. In that case a-b would be an identifier and a - b would be the operation. Just as in python fromAimportB is an identifier and from A import B is an import statement. -- Antoon Pardon