Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!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.020 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'collections': 0.09; 'instances.': 0.09; 'tuple': 0.09; 'tuple.': 0.09; 'typeerror:': 0.09; 'cc:addr:python-list': 0.10; 'passing': 0.15; 'cc:name:python list': 0.16; 'clarified': 0.16; 'created.': 0.16; 'namedtuple': 0.16; 'namedtuples': 0.16; 'tuple)': 0.16; 'wrote:': 0.17; 'items.': 0.17; '>>>': 0.18; 'import': 0.21; 'error.': 0.21; 'developers.': 0.22; 'tuples': 0.22; 'example': 0.23; 'specified': 0.23; "haven't": 0.23; 'seems': 0.23; 'feature': 0.24; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'wondering': 0.26; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'oversight': 0.29; "i'm": 0.29; 'code': 0.31; 'point': 0.31; 'suggestion': 0.32; 'could': 0.32; 'hi,': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'list': 0.35; 'expected': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'author': 0.37; 'two': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'john': 0.60; 'more.': 0.62; 'between': 0.63; 'different': 0.63; 'offer': 0.65; 'differences': 0.65; 'hoping': 0.72; '2013': 0.84; 'construct': 0.84; 'oscar': 0.84; 'reid': 0.84; 'replacements': 0.84; 'do:': 0.91; 'angel': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=volfx4JyNuD8hC/EHzEiCPQIW8Qq7mMVNPa2Ao5kV2U=; b=JlLp9fZ15yysf+vlyJ44DmQEwMpLWIPpEXHhqHjXJuZ03oMhG2wdQ9i7x0jHT4atcu lC1s1TgQCIcFJ6Ai5laaO9la3goyLLynvDz8uasHejTgFzrXc11xAVTp9/Me8wNVHGNO aSkUygoa2Cn7oqQxgr8MzmXbCsz8Z7liaXzZ3nf5q9n9p1n8HEpWpNjUSf/qOtQIG28e ZOgViGfcrzBQJ689VdAAz9y1fHphaNxGI9fm7roYUL+cL915RrzdTCymwCbpEl+NPose tRyCVhg9n8IYyBu8BphNgpDTwy6kS28226TWVDC0B0fK4ZRpyoHnI/htlDfIYrMT4gT7 BMlw== X-Received: by 10.52.71.235 with SMTP id y11mr13416781vdu.43.1361196970342; Mon, 18 Feb 2013 06:16:10 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <5122360C.20603@mail.cryst.bbk.ac.uk> References: <7a40a426-baa9-46f8-8f9d-59ba32b044f3@googlegroups.com> <51221A6C.3030804@davea.name> <5122360C.20603@mail.cryst.bbk.ac.uk> From: Oscar Benjamin Date: Mon, 18 Feb 2013 14:15:50 +0000 Subject: Re: Differences creating tuples and collections.namedtuples To: John Reid Content-Type: text/plain; charset=ISO-8859-1 Cc: Python List 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361196973 news.xs4all.nl 6876 [2001:888:2000:d::a6]:45960 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39093 On 18 February 2013 14:09, John Reid wrote: > On 18/02/13 12:11, Dave Angel wrote: >> On 02/18/2013 06:47 AM, John Reid wrote: >>> Hi, >>> >>> I was hoping namedtuples could be used as replacements for tuples in >>> all instances. There seem to be some differences between how tuples >>> and namedtuples are created. For example with a tuple I can do: >>> >>> a=tuple([1,2,3]) >>> >>> with namedtuples I get a TypeError: >>> >>> from collections import namedtuple >>> B=namedtuple('B', 'x y z') >>> b=B([1,2,3]) >> >> You are passing a single list to the constructor, but you specified that >> the namedtuple was to have 3 items. So you need two more. > > 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. I would say that depending on isinstance(obj, tuple) was the error. I can't offer a suggestion as you haven't clarified what the purpose of this code in canSequence() is or what constraints it is expected to satisfy. Oscar