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

Jeremy Hylton jhylton at gmail.com
Fri Aug 27 18:30:17 CEST 2004


On Thu, 26 Aug 2004 19:12:30 -0400, David Abrahams
<dave at boost-consulting.com> wrote:
> 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.

It's a fair complaint.  I've made the mistake myself, and it usually
takes a few head scratching and investigation before I realize that
I'm passing a string instead of some other sequence.  On the other
hand, I like slicing lists and occasionally I iterate over their
characters.  What's the alternative?  A typecheck seems like it would
be handy, but I'm not sure what type I would want "all sequences
except strings"?

Jeremy


More information about the Python-Dev mailing list