Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.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; 'ascii': 0.07; 'attribute': 0.07; 'bug.': 0.07; 'received:verizon.net': 0.07; 'terry': 0.07; 'will,': 0.07; 'python': 0.08; 'dict': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'tuple': 0.09; 'tuple.': 0.09; 'am,': 0.12; '11/10/2011': 0.16; '3:51': 0.16; 'objects).': 0.16; 'py3': 0.16; 'reedy': 0.16; 'subject:() ': 0.16; 'wrote:': 0.18; 'jan': 0.19; "doesn't": 0.23; 'header:In-Reply-To:1': 0.23; 'function': 0.27; 'fact': 0.27; 'bit': 0.28; 'unicode': 0.28; 'members.': 0.30; '(e.g.': 0.30; 'subject:?': 0.31; 'quite': 0.32; 'to:addr:python-list': 0.32; 'someone': 0.33; 'instead': 0.33; 'header:User-Agent:1': 0.33; 'header:X-Complaints-To:1': 0.33; 'setting': 0.34; 'try:': 0.34; 'object': 0.35; 'another': 0.36; 'plans': 0.37; 'received:org': 0.37; 'expensive': 0.38; 'should': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; 'supports': 0.40; 'more': 0.60; 'accepts': 0.64; 'specialized': 0.72; 'virtually': 0.73 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: all() is slow? Date: Thu, 10 Nov 2011 14:25:40 -0500 References: <436fb6a3-1075-45a6-8f93-5612d050b11a@q35g2000prh.googlegroups.com> <4eb9e9c2$0$29988$c3e8da3$5496439d@news.astraweb.com> <4ebb08b6$0$29970$c3e8da3$5496439d@news.astraweb.com> <4ebb81e1$0$29988$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-74-109-121-73.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1320953170 news.xs4all.nl 6946 [2001:888:2000:d::a6]:54057 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15554 On 11/10/2011 3:51 AM, Devin Jeanpierre wrote: >> Because Python doesn't allow "--" to be an attribute name, and so >> namedtuple doesn't let you try: >> >> t = namedtuple("T", "foo -- bar")(1, 2, 3) >> print(t.foo) >> print(t.--) >> print(t.bar) > > '--' is a valid attribute name on virtually any object that supports > attribute setting (e.g. function objects). ob.-- is not valid Python because '--' is not a name. > Of course, you need to use setattr() and getattr(). I consider the fact that CPython's setattr accepts non-name strings to be a bit of a bug. Or if you will, leniency for speed. (A unicode name check in Py3 would be much more expensive than an ascii name check in Py2.) I would consider it legitimate for another implementation to only accept names and to use a specialized name_dict for attribute dictionaries. So I consider it quite legitimate for namedtuple to requires real names for the fields. The whole point is to allow ob.name access to tuple members. Someone who plans to use set/getattr with arbitrary strings should just use a dict instead of a tuple. -- Terry Jan Reedy