[BangPypers] Nice "feature"

Hussain Bohra hussainbohra_30 at yahoo.com
Fri Apr 1 15:14:04 CEST 2011


Atleast on changing list, you gets an exception. 

On updating dictionary living inside tuple wont throw an exception as well.

>>> foo = (1,[2,3,4], {'a':1})
>>> foo[2].update({'b':2})
>>> foo
(1, [2, 3, 4], {'a': 1, 'b': 2})
>>>

Both python 2.6 and 3.1 behaves in the same way.
 
Thanks and Regards,
Hussain Bohra
Tavant Technologies,
Bangalore-95
mail-to:hussain.bohra at tavant.com
mobile : +91 99867 95727





________________________________
From: Navin Kabra <navin.kabra at gmail.com>
To: Bangalore Python Users Group - India <bangpypers at python.org>
Sent: Fri, 1 April, 2011 6:25:03 PM
Subject: Re: [BangPypers] Nice "feature"

With Python 2.6.5 (on ubuntu) I get even more bizarre behavior:
>>> foo=(1,[2,3,4])
>>> foo[1]+=6
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
>>> foo
(1, [8, 9, 10])




On Fri, Apr 1, 2011 at 6:17 PM, Noufal Ibrahim <noufal at gmail.com> wrote:

>
> Came across this at PyCon. Comments?
>
> >>> foo = (1,[2,3,4])
> >>> foo[1] += [6]
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> TypeError: 'tuple' object does not support item assignment
> >>> foo
> (1, [2, 3, 4, 6])
> >>>
>
> --
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>
_______________________________________________
BangPypers mailing list
BangPypers at python.org
http://mail.python.org/mailman/listinfo/bangpypers


More information about the BangPypers mailing list