[Python-bugs-list] [ python-Bugs-811604 ] "string".split behaviour
for empty strings
SourceForge.net
noreply at sourceforge.net
Fri Sep 26 07:04:54 EDT 2003
Bugs item #811604, was opened at 2003-09-24 13:50
Message generated for change (Comment added) made by meyarivan
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: Open
Resolution: None
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: T.Meyarivan (meyarivan)
Date: 2003-09-26 16:34
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 10:05
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 14:21
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