[Tutor] totalViruses[i] /= float(numTrials),

eryksun eryksun at gmail.com
Thu Apr 25 01:50:23 CEST 2013


On Wed, Apr 24, 2013 at 6:58 PM, Oscar Benjamin
<oscar.j.benjamin at gmail.com> wrote:
> And here's another example:
>>>> c = ([],)
>>>> c
> ([],)
>>>> c[0] = c[0] + [1]
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: 'tuple' object does not support item assignment
>>>> c
> ([],)
>>>> c[0] += [1]
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: 'tuple' object does not support item assignment
>>>> c
> ([1],)

The interpreter always uses a STORE operation after an in-place
operation because it doesn't know if the target object was mutated
in-place -- not with how it's currently implemented in ceval.c (in
principle it could). This leads to half-completed operations that
raise a TypeError like this when it tries to store the mutated object
back to an immutable container. This can happen with any object that
doesn't support assigning to subscripts or attributes, not just a
tuple.


More information about the Tutor mailing list