a splitting headache

Mensanator mensanator at aol.com
Thu Oct 22 02:31:05 EDT 2009


On Oct 21, 11:21�pm, John Yeung <gallium.arsen... at gmail.com> wrote:
> On Oct 21, 5:43�pm, Mensanator <mensana... at aol.com> wrote:
>
> > >>> '010000110'.split('0')
>
> > ['', '1', '', '', '', '11', '']
>
> > is a perfect example. It shows the empty strings
> > generated from the leading and trailing delimiters,
> > and also that you get 3 empty strings between the
> > '1's, not 4. When creating documentation, it is
> > always a good idea to document such cases.
>
> It's documented. �

What does 'it' refer to? A leading or trailing
delimiter? That's what _I_ was refering to.

> It's even in the example

No, it is not.

> (that you cited yourself):
>
> � '1,,2'.split(',') returns ['1', '', '2']
>
> There are two commas between the '1' and the '2', but "only" one empty
> string between them. �To me, it's obvious that
>
> � '1,,2'.split(',')
>
> is equivalent to
>
> � '1002'.split('0')

That wasn't what I was complaining about.

>
> > And you'll then want to compare this to the
> > equivalent whitespace case:
>
> > >>> ' 1 � �11 '.split()
> > ['1', '11']
>
> The documentation could not be more explicit that when the separator
> is not specified or is None, it behaves very differently.

I am not complaining that it behaves differently, but
the description of said difference could be better
explained.

>
> Have you tried to see what happens with
>
> � ' 1 � �11 '.split(' ')

Yes, I actually did that test.

>
> (Hint: �The separator is (a kind of) white space... yet IS specified.

And yet doesn't behave like .split(). In other words,
when specified, whitespace does not behave like
whitespace. Is it any wonder I have a headache?

>)
>
> > I was looking for some feedback here.
> > And it seems that no one else considers the
> > documentation wanting.
>
> This particular section of documentation, no. �I have issues with some
> of the documentation here and there; this is not one of those areas.
>
> You kept using phrases in your arguments like "Yes, if you
> think it through" and "An example would at least force me to think
> about it". �Um... are we not supposed to think?

No, you are not. Documentation isn't supposed to give
you hints so that you can work out the way things
behave. It should provide adequete explantion along
with unambiguous, complete examples. The thinking part
comes into play as you try to figure out how to apply
what you have just learned.

>
> John




More information about the Python-list mailing list