[ python-Bugs-811604 ] "string".split behaviour for empty strings
SourceForge.net
noreply at sourceforge.net
Sun Mar 21 12:11:11 EST 2004
Bugs item #811604, was opened at 2003-09-24 04:20
Message generated for change (Comment added) made by mondragon
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=811604&group_id=5470
Category: Python Interpreter Core
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: T.Meyarivan (meyarivan)
Assigned to: Nobody/Anonymous (nobody)
Summary: "string".split behaviour for empty strings
Initial Comment:
"".split() -> []
"".split(' ') -> ['']
It is not clear from the documentation as to what is
the defined behaviour in the above case. To say the
least, it is
completely counter-intuitive..(splitting an empty
string should
return the list [''] in both cases).
>From stringobject.c, the behaviour of split_whitespace
(i.e split called without sep) and string_split (split
called with sep) is different for empty
strings..perhaps the function split_whitespace needs to
be patched.
----------------------------------------------------------------------
>Comment By: Nick Bastin (mondragon)
Date: 2004-03-21 12:11
Message:
Logged In: YES
user_id=430343
Fixed in doc/lib/libstring.tex version 1.57
----------------------------------------------------------------------
Comment By: Terry J. Reedy (tjreedy)
Date: 2003-09-28 19:50
Message:
Logged In: YES
user_id=593130
Suggestion: find section of Lib Ref discussing str.split, quote
existing def, and add succinct sentence that you think is
needed. Then change category to 'documentation' so
appropriate person(s) will see proposal.
----------------------------------------------------------------------
Comment By: T.Meyarivan (meyarivan)
Date: 2003-09-26 07:04
Message:
Logged In: YES
user_id=30470
Thats so counter intuitive.. :-(
At least the documentation should specify the fact that the
behaviour of "string".split for empty strings is so and so....
The reason this probably never came up ( or mostly ignored
by majority ) is that people probably check if the string is
empty before proceeding to process it..
I am not closing the bug before the specific behaviour of
"string".split for empty strings gets to the docs..
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2003-09-26 00:35
Message:
Logged In: YES
user_id=80475
And so it is. The whitespace version (no args) and the
specified separator version work differently -- the second
version can never return an empty list.
This code has been around for a good while and it is likely
that much code relies on the behavior, so I recommend
classifying it as a beauty spot and closing the bug.
"One man's bug is another man's feature"
----------------------------------------------------------------------
Comment By: T.Meyarivan (meyarivan)
Date: 2003-09-24 04:51
Message:
Logged In: YES
user_id=30470
"".split(None) -> []
which is expected because in the case when no sep is
specified and when sep == None, split_whitespace is called..
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=811604&group_id=5470
More information about the Python-bugs-list
mailing list