Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'case.': 0.05; 'arguments': 0.07; 'matched': 0.09; 'repr': 0.09; 'to:addr:comp.lang.python': 0.09; 'tuple.': 0.09; 'unpacking': 0.09; 'cc:addr:python-list': 0.10; '1))': 0.16; '__new__': 0.16; 'iterable': 0.16; 'namedtuple': 0.16; 'tuples,': 0.16; 'wrote:': 0.17; 'usability': 0.17; 'developers.': 0.22; 'latter': 0.22; 'cc:2**0': 0.23; 'monday,': 0.23; 'raymond': 0.23; 'this:': 0.23; 'seems': 0.23; 'cc:no real name:2**0': 0.24; 'feature': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'wondering': 0.26; 'regular': 0.27; 'arguments.': 0.29; 'oversight': 0.29; "i'm": 0.29; "skip:' 10": 0.30; 'keyword': 0.30; 'primary': 0.30; 'point': 0.31; 'instances': 0.33; 'instead,': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'ability': 0.36; 'created': 0.36; 'author': 0.37; 'signature': 0.37; 'received:209': 0.37; 'received:209.85.216': 0.37; 'subject:: ': 0.38; 'help': 0.40; 'your': 0.60; 'decision': 0.60; 'from:no real name:2**0': 0.60; 'john': 0.60; 'different': 0.63; 'skip:n 10': 0.63; 'lose': 0.71; 'as:': 0.75; 'prompt': 0.78; '2013': 0.84; 'choices:': 0.84; 'construct': 0.84; 'reid': 0.84; 'write:': 0.91 X-Received: by 10.50.217.161 with SMTP id oz1mr1913839igc.3.1361260126851; Mon, 18 Feb 2013 23:48:46 -0800 (PST) Newsgroups: comp.lang.python Date: Mon, 18 Feb 2013 23:48:46 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=67.160.192.255; posting-account=vooLmAoAAADWWfQb9CqaOUK6tD-uS-EU References: <7a40a426-baa9-46f8-8f9d-59ba32b044f3@googlegroups.com> <51221A6C.3030804@davea.name> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 67.160.192.255 MIME-Version: 1.0 Subject: Re: Differences creating tuples and collections.namedtuples From: raymond.hettinger@gmail.com To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361260822 news.xs4all.nl 6888 [2001:888:2000:d::a6]:38135 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39190 On Monday, February 18, 2013 6:09:16 AM UTC-8, John Reid wrote: > I'm aware how to construct the namedtuple and the tuple. My point was > that they use different syntaxes for the same operation and this seems > to break ipython. I was wondering if this is a necessary design feature > or perhaps just an oversight on the part of the namedtuple author or > ipython developers. It was not an oversight on the part of the namedtuple author. It was a deliberate design decision to improve usability for named tuple's primary use case. Consider a namedtuple such as: Person =3D namedtuple('Person', ['name', 'rank', 'serial_number']) With the current signature, instances can be created like this: p =3D Person('Guido', 'BDFL', 1) If instead, the __new__ signature matched that of regular tuples, you would need to write: p =3D Person(('Guido', 'BDFL', 1)) The double parens are awkward. You would lose tooltips that prompt you for= Person(name, rank, serial_number). You would lose the ability to use keyw= ord arguments such as Person(rank=3D'BDFL', serial_number=3D1, name=3D'Guid= o') or Person(**d). The repr for the namedtuple would lose its eval(repr(t= )) roundtrip property. =20 If your starting point is an existing iterable such as s=3D['Guido', 'BDFL'= , 1], you have a couple of choices: p=3DPerson(*s) or p=3DPerson._make(s)= . The latter form was put it to help avoid unpacking and repacking the arg= uments. =20 Raymond