[Python-Dev] Re: list += string??

David Abrahams dave at boost-consulting.com
Fri Aug 27 01:12:30 CEST 2004


David Abrahams <dave at boost-consulting.com> writes:

>> It was new when the iterator protocol was introduced.  It wasn't
>> explicitly intended that you get surprises for strings
>> specifically, but it was explicitly intended that
>>
>>     list += whatever
>>
>> work like
>>
>>     list.extend(whatever)
>>
>> and that whatever can be any iterable object.
>
>
> I figured as much.

Report from the field: I just discovered a bug that's been hiding in
my code for a few months.  The code was being exercised, but the
result was the same as if the code had been correct until I threw
some new examples at it.  The problem was:

   self.body[e[0]:e[1]] = s

self.body is a list of strings, and s is a string.  Later
''.join(self.body) gets called, so for many cases the bug was hidden.
No offense intended (okay, maybe a tiny little offense), but the
experience here is a bit Perl-like.

>> Since strings are iterable objects, it's no more or less surprising
>> than that 'for ch in "bomb"' works too <wink>.
>
> I want my ,= operator!

I still do, but it wouldn't have solved _this_ problem.

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com



More information about the Python-Dev mailing list