Is this a bug?
Grant Edwards
grante at visi.com
Sun Apr 24 11:38:29 EDT 2005
On 2005-04-24, Michael Sparks <zathras at thwackety.com> wrote:
>>>> a=["hello"]
>>>> a = a + "world"
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: can only concatenate list (not "str") to list
> However if we do this just slightly differently:
>
>>>> a = ["hello"]
>>>> a += "world"
>>>> a
> ['hello', 'w', 'o', 'r', 'l', 'd']
>
> We get completely different behaviour. This strikes me as a bug - should I
> log it as one, or is there a good reason for this behaviour?
I think it's a bug regardless of the reason for the behavior:
1) It doesn't do what a reasonable user expects.
2) It doesn't do what the documentation says it will.
According to the language reference,
An augmented assignment expression like x += 1 can be
rewritten as x = x + 1 to achieve a similar, but not
exactly equal effect. In the augmented version, x is only
evaluated once.
I don't consider the two results you posted "similar".
--
Grant Edwards grante Yow! TAILFINS!!...click...
at
visi.com
More information about the Python-list
mailing list