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


Groups > comp.lang.python > #67158

Re: Tuples and immutability

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <zachary.ware@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'assign': 0.07; 'assignment': 0.07; 'result,': 0.07; 'explanation': 0.09; 'cc:addr :python-list': 0.11; 'wrote': 0.14; 'attempted': 0.16; 'did,': 0.16; 'expected,': 0.16; 'index.': 0.16; 'least.': 0.16; 'operation,': 0.16; 'url:faq': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'trying': 0.19; 'thu,': 0.19; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'exists': 0.24; 'faq': 0.24; 'questions:': 0.24; 'looks': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'extension': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'on,': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'context.': 0.31; 'url:python': 0.33; 'not.': 0.33; 'point.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'entry': 0.36; 'url:org': 0.36; 'should': 0.36; 'half': 0.37; 'being': 0.38; 'though,': 0.39; 'then,': 0.60; 'url:3': 0.61; "you're": 0.61; 'first': 0.61; 'linked': 0.65; 'to:addr:gmail.com': 0.65; 'implications': 0.84; 'tricky': 0.84; 'ware': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=qCxqMrbEnj38tAIXv/bF8YgdevtvvACtvrusGcTILfE=; b=OG3ASBjlbX3PPeAXSFJJA/4cIazcOnGqiHoQxM/ohL4CYlYgKFxWuPH2dhT3W1x1gB PV8AUxOerlzDxsxTHNZnGmnUMrbC1zh6qyQaRSUDv99UFoCh/Hc+jzFbEk1XM0MdQeL7 r1LdjXZYszCocvPEFL/eHRvsEs0CTP7zQEAixWDkPArW2jBuveUCCFPTfqQMutbftbIl 2Du2s6Md505TXhYvtLP+wozEHvq0UCONyTucWZHDnvNL3+lWMW6ELfW2ACKjX/OfUUoE dygD8sBjhnTxI8o3nPxE/pgzkCeYw3P29xn01TzMaPbvdy25c5/ovovK6VBiI3pQ1vgw NnCg==
X-Received by 10.204.168.72 with SMTP id t8mr21146bky.115.1393519649996; Thu, 27 Feb 2014 08:47:29 -0800 (PST)
MIME-Version 1.0
Sender zachary.ware@gmail.com
In-Reply-To <lenp14$m8f$1@cabale.usenet-fr.net>
References <lennh4$kpm$1@cabale.usenet-fr.net> <mailman.7427.1393517631.18130.python-list@python.org> <lenp14$m8f$1@cabale.usenet-fr.net>
From Zachary Ware <zachary.ware+pylist@gmail.com>
Date Thu, 27 Feb 2014 10:47:09 -0600
X-Google-Sender-Auth XaluY2zIsufYYSXT2g94tNjLqyY
Subject Re: Tuples and immutability
To Eric Jacoboni <eric.jacoboni@gmail.com>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc "python-list@python.org" <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.7431.1393519651.18130.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1393519651 news.xs4all.nl 2962 [2001:888:2000:d::a6]:34409
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:67158

Show key headers only | View raw


On Thu, Feb 27, 2014 at 10:27 AM, Eric Jacoboni <eric.jacoboni@gmail.com> wrote:
> Le 27/02/2014 17:13, Zachary Ware a écrit :
>>
>> You're not the first person to have this question :)
>>
>> http://docs.python.org/3/faq/programming.html#why-does-a-tuple-i-item-raise-an-exception-when-the-addition-works
>>
>
> Oh yes, i was aware of this explanation (thanks to Chris for his answer,
> too)... and that's why i wrote "reasonable" :)
> I know i should use append() or extend() and i understand the tricky
> implications of += in this context. But, imho, it's far from being a
> intuitive result, to say the least.

Well, once you understand what's actually going on, it's the result
that you should expect.  The FAQ entry I linked to exists to help
people get to that point.

To answer your specific questions:

> But, then, why a_tuple is still modified?

It is not.  a_tuple is still "('spam', <list object at specific
address>, 'eggs')", exactly the same before and after the attempted
"a_tuple[1] += [20]".  The change is internal to <list object at
specific address>.

> I get a TypeError for an illegal operation, but this operation is still
> completed?

Half completed.  The extension of <list object at specific address>
happened as expected, but the assignment of <list object at specific
address> to a_tuple[1] didn't.  It looks like it did, though, because
the assignment was just trying to assign the same object to the same
index.

-- 
Zach

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


Thread

Tuples and immutability Eric Jacoboni <eric.jacoboni@gmail.com> - 2014-02-27 17:01 +0100
  Re: Tuples and immutability Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-02-27 10:13 -0600
    Re: Tuples and immutability Eric Jacoboni <eric.jacoboni@gmail.com> - 2014-02-27 17:27 +0100
      Re: Tuples and immutability Chris Angelico <rosuav@gmail.com> - 2014-02-28 03:33 +1100
      Re: Tuples and immutability Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-02-27 10:47 -0600
      Re: Tuples and immutability Nick Timkovich <prometheus235@gmail.com> - 2014-02-27 15:47 -0600
      Re: Tuples and immutability Chris Angelico <rosuav@gmail.com> - 2014-02-28 08:52 +1100
      Re: Tuples and immutability Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-27 15:18 -0700
      Re: Tuples and immutability Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2014-03-01 18:55 +0000
  Re: Tuples and immutability Chris Angelico <rosuav@gmail.com> - 2014-02-28 03:14 +1100
  Re: Tuples and immutability Marko Rauhamaa <marko@pacujo.net> - 2014-02-27 18:19 +0200
    Re: Tuples and immutability John O'Hagan <research@johnohagan.com> - 2014-02-28 16:17 +1100
      Re: Tuples and immutability Marko Rauhamaa <marko@pacujo.net> - 2014-02-28 09:54 +0200
  Re: Tuples and immutability Joshua Landau <joshua@landau.ws> - 2014-02-28 14:41 +0000
  Re: Tuples and immutability Chris Angelico <rosuav@gmail.com> - 2014-03-01 01:43 +1100
  Re: Tuples and immutability "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-28 16:22 -0800
    Re: Tuples and immutability Eric Jacoboni <eric.jacoboni@gmail.com> - 2014-03-01 02:27 +0100
      Re: Tuples and immutability "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-28 20:45 -0800
        Re: Tuples and immutability Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-28 22:34 -0700
          Re: Tuples and immutability "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-28 21:50 -0800
            Re: Tuples and immutability Ned Batchelder <ned@nedbatchelder.com> - 2014-03-01 12:56 -0500
      Re: Tuples and immutability Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-28 22:26 -0700
    Re: Tuples and immutability Chris Angelico <rosuav@gmail.com> - 2014-03-01 12:39 +1100
    Re: Tuples and immutability Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-28 22:16 -0700
      Re: Tuples and immutability "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-28 22:16 -0800
        Re: Tuples and immutability Chris Angelico <rosuav@gmail.com> - 2014-03-01 17:29 +1100
        Re: Tuples and immutability Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-01 14:54 +0000
          Re: Tuples and immutability "Mark H. Harris" <harrismh777@gmail.com> - 2014-03-01 13:01 -0800
      Re: Tuples and immutability "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-28 22:25 -0800
        Re: Tuples and immutability Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-01 12:45 -0700
      Re: Tuples and immutability "Mark H. Harris" <harrismh777@gmail.com> - 2014-03-01 13:21 -0800
        Re: Tuples and immutability Eric Jacoboni <eric.jacoboni@gmail.com> - 2014-03-02 03:04 +0100
          Re: Tuples and immutability "Mark H. Harris" <harrismh777@gmail.com> - 2014-03-01 18:28 -0800
          Re: Tuples and immutability Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-02 05:32 -0700
            Re: Tuples and immutability Eric Jacoboni <eric.jacoboni@gmail.com> - 2014-03-02 14:38 +0100
              Re: Tuples and immutability Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-02 14:05 +0000
                Re: Tuples and immutability Eric Jacoboni <eric.jacoboni@gmail.com> - 2014-03-02 15:17 +0100
                Re: Tuples and immutability "albert visser" <albert.visser@gmail.com> - 2014-03-02 15:37 +0100
        Re: Tuples and immutability "Mark H. Harris" <harrismh777@gmail.com> - 2014-03-01 18:15 -0800

csiph-web