[Python-Dev] Re: Bug 911080, string split oddness

Pete Shinners pete at shinners.org
Sun Mar 7 01:12:12 EST 2004


Jeff Epler wrote:
> I think the current version documentation intends to explain the
> no-argument form with this sentence:
>     If sep is not specified or None, any whitespace string is a separator.
>     [http://python.org/doc/current/lib/string-methods.html#l2h-197]

I'm having a hard time making this clear. By reading the documentation I 
would guess that "split()" would be equivalent to 
"split(string.whitespace)". In fact they work very differently.

With no separator argument, the separators are grouped. The problem comes 
when your splitted string has multiple separators next to each other. To 
make them work the same is more like this

   mystr.split()
   filter(None, mystr.split(string.whitespace))




More information about the Python-Dev mailing list