Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"string".split behaviour for empty strings #39287

Closed
meyarivan mannequin opened this issue Sep 24, 2003 · 6 comments
Closed

"string".split behaviour for empty strings #39287

meyarivan mannequin opened this issue Sep 24, 2003 · 6 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@meyarivan
Copy link
Mannequin

meyarivan mannequin commented Sep 24, 2003

BPO 811604
Nosy @rhettinger, @terryjreedy

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2004-03-21.17:11:10.000>
created_at = <Date 2003-09-24.08:20:19.000>
labels = ['interpreter-core']
title = '"string".split behaviour for empty strings'
updated_at = <Date 2004-03-21.17:11:10.000>
user = 'https://bugs.python.org/meyarivan'

bugs.python.org fields:

activity = <Date 2004-03-21.17:11:10.000>
actor = 'nbastin'
assignee = 'none'
closed = True
closed_date = None
closer = None
components = ['Interpreter Core']
creation = <Date 2003-09-24.08:20:19.000>
creator = 'meyarivan'
dependencies = []
files = []
hgrepos = []
issue_num = 811604
keywords = []
message_count = 6.0
messages = ['18312', '18313', '18314', '18315', '18316', '18317']
nosy_count = 4.0
nosy_names = ['rhettinger', 'terry.reedy', 'nbastin', 'meyarivan']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue811604'
versions = []

@meyarivan
Copy link
Mannequin Author

meyarivan mannequin commented Sep 24, 2003

"".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.

@meyarivan meyarivan mannequin closed this as completed Sep 24, 2003
@meyarivan meyarivan mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Sep 24, 2003
@meyarivan meyarivan mannequin closed this as completed Sep 24, 2003
@meyarivan meyarivan mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Sep 24, 2003
@meyarivan
Copy link
Mannequin Author

meyarivan mannequin commented Sep 24, 2003

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..

@rhettinger
Copy link
Contributor

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"

@meyarivan
Copy link
Mannequin Author

meyarivan mannequin commented Sep 26, 2003

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..

@terryjreedy
Copy link
Member

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.

@nbastin
Copy link
Mannequin

nbastin mannequin commented Mar 21, 2004

Logged In: YES
user_id=430343

Fixed in doc/lib/libstring.tex version 1.57

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)
Projects
None yet
Development

No branches or pull requests

2 participants