Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #60981

Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
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; 'dynamically': 0.07; 'attributes': 0.09; 'subject:Why': 0.09; 'cc:addr:python-list': 0.11; '-tkc': 0.16; 'descriptors.': 0.16; 'effect.': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'identifiers': 0.16; 'key/value': 0.16; 'piotr': 0.16; 'subject: \n ': 0.16; 'subject:accessing': 0.16; 'variable.': 0.16; 'way;': 0.16; 'prevent': 0.16; 'wrote:': 0.18; 'pfxlen:0': 0.19; 'later': 0.20; 'meant': 0.20; 'saying': 0.22; 'tests': 0.22; 'cc:addr:python.org': 0.22; "aren't": 0.24; 'driven': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'testing': 0.29; "doesn't": 0.30; 'code': 0.31; 'names.': 0.31; 'table': 0.34; 'could': 0.34; 'subject:with': 0.35; 'something': 0.35; 'objects': 0.35; 'test': 0.35; 'but': 0.35; 'accessing': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'being': 0.38; 'most': 0.60; 'name': 0.63; 'skip:n 10': 0.64; 'side': 0.67; 'frequently': 0.68; 'subject:there': 0.68; 'received:50.22': 0.84; 'subject:being': 0.84; 'to:addr:p': 0.84
Date Tue, 3 Dec 2013 19:06:44 -0600
From Tim Chase <python.list@tim.thechases.com>
To Piotr Dobrogost <p@google-groups-2013.dobrogost.net>
Subject Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers?
In-Reply-To <eb15e1a8-49b1-4d55-a864-141efc65394e@googlegroups.com>
References <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <mailman.3527.1386093834.18130.python-list@python.org> <eb15e1a8-49b1-4d55-a864-141efc65394e@googlegroups.com>
X-Mailer Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
X-Get-Message-Sender-Via boston.accountservergroup.com: authenticated_id: tim@thechases.com
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3543.1386119133.18130.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1386119133 news.xs4all.nl 2928 [2001:888:2000:d::a6]:41047
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:60981

Show key headers only | View raw


On 2013-12-03 15:47, Piotr Dobrogost wrote:
> > The getattr function is meant for when your attribute name is in a
> > variable. Being able to use strings that aren't valid identifiers
> > is a side effect.   
> 
> Why do you say it's a side effect?

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.

I see non-traditional-identifiers most frequently in test code where
the globals() dictionary gets injected with various objects for
testing purposes, driven by a table with descriptors.  Something like
(untested)

  tests = [
     dict(desc="Test 1", input=10, expected=42),
     dict(desc="Test 2", input=314, expected=159),
     ]
  for test in tests:
    test_name = "test_" + test["desc"]
    globals()[test_name] = generate_test_function(
       test["input"], test["output"])

-tkc


Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-03 09:14 -0800
  Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ned Batchelder <ned@nedbatchelder.com> - 2013-12-03 12:38 -0500
  Re: Why is there no natural syntax for accessing attributes with names
 not being valid identifiers? Dave Angel <davea@davea.name> - 2013-12-03 12:48 -0500
    Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-04 14:05 -0800
      Re: Why is there no natural syntax for accessing attributes with
 names not being valid identifiers? Dave Angel <davea@davea.name> - 2013-12-04 17:28 -0500
  Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ethan Furman <ethan@stoneleaf.us> - 2013-12-03 09:31 -0800
    Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-03 15:49 -0800
  Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? random832@fastmail.us - 2013-12-03 13:03 -0500
    Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-03 15:47 -0800
      Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Tim Chase <python.list@tim.thechases.com> - 2013-12-03 19:06 -0600
        Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-04 12:35 -0800
          Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-04 20:46 +0000
          Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Jerry Hill <malaclypse2@gmail.com> - 2013-12-04 15:58 -0500
          Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ethan Furman <ethan@stoneleaf.us> - 2013-12-04 13:02 -0800
          Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Neil Cerutti <neilc@norwich.edu> - 2013-12-04 21:41 +0000
            Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-04 13:54 -0800
              Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Neil Cerutti <neilc@norwich.edu> - 2013-12-06 14:07 +0000
                Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-06 08:51 -0800
                Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Rotwang <sg552@hotmail.co.uk> - 2013-12-07 00:47 +0000
            Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-04 14:13 -0800
              Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ethan Furman <ethan@stoneleaf.us> - 2013-12-04 15:09 -0800
                Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-04 15:57 -0800
                Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ethan Furman <ethan@stoneleaf.us> - 2013-12-04 16:26 -0800
                Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ned Batchelder <ned@nedbatchelder.com> - 2013-12-04 20:17 -0500
          Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Terry Reedy <tjreedy@udel.edu> - 2013-12-04 21:58 -0500
          Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ethan Furman <ethan@stoneleaf.us> - 2013-12-04 19:05 -0800
          Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Steven D'Aprano <steve@pearwood.info> - 2013-12-05 07:56 +0000
      Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Tim Roberts <timr@probo.com> - 2013-12-03 21:45 -0800
        Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? rusi <rustompmody@gmail.com> - 2013-12-03 22:31 -0800
          Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ian Kelly <ian.g.kelly@gmail.com> - 2013-12-04 01:57 -0700
            Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? rusi <rustompmody@gmail.com> - 2013-12-04 02:09 -0800
              Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-12-04 11:29 +0100
                Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? rusi <rustompmody@gmail.com> - 2013-12-04 04:01 -0800
                Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-12-04 13:32 +0100
                Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? rusi <rustompmody@gmail.com> - 2013-12-04 05:02 -0800
                Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-12-04 20:57 +0100
              Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Chris Angelico <rosuav@gmail.com> - 2013-12-04 21:33 +1100
                Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? rusi <rustompmody@gmail.com> - 2013-12-04 03:27 -0800
              Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Tim Chase <python.list@tim.thechases.com> - 2013-12-04 05:25 -0600
              Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-12-04 13:30 +0200
                Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Chris Angelico <rosuav@gmail.com> - 2013-12-04 22:40 +1100
                Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ethan Furman <ethan@stoneleaf.us> - 2013-12-04 07:56 -0800
              Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ian Kelly <ian.g.kelly@gmail.com> - 2013-12-04 19:43 -0700
                Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? rusi <rustompmody@gmail.com> - 2013-12-04 20:48 -0800
          Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-04 19:27 -0500
            Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Roy Smith <roy@panix.com> - 2013-12-04 20:03 -0500
        Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ethan Furman <ethan@stoneleaf.us> - 2013-12-04 01:12 -0800
        Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Roy Smith <roy@panix.com> - 2013-12-04 08:23 -0500
          Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-04 13:00 -0800
        Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-04 12:07 -0800
          Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ethan Furman <ethan@stoneleaf.us> - 2013-12-04 12:22 -0800
          Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-04 20:55 +0000
          Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ethan Furman <ethan@stoneleaf.us> - 2013-12-04 13:00 -0800
          Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Terry Reedy <tjreedy@udel.edu> - 2013-12-04 17:11 -0500
            Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-04 15:42 -0800
              Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Terry Reedy <tjreedy@udel.edu> - 2013-12-04 22:21 -0500
          Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Rotwang <sg552@hotmail.co.uk> - 2013-12-05 01:50 +0000

csiph-web