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
Undocumented implicit strip() in split(None) string method #41462
Comments
Hi! I noticed that the string method split() first does an Example 1: s.split() then returns ['word1', 'word2'] and not ['', WHY IS THIS BAD?
Let sHeader be a Python string containing a FASTA sID = sHeader[1:].split(None, 1)[0] However, this does not work if sHeader contains a WHAT SHOULD BE DONE? The implicit strip() should be removed, or at least Thank you for an otherwise splendid language! |
Logged In: YES I think the docs for split() under "String Methods" are quite """ If sep is not specified or is None, a different splitting This won't change, because mountains of code rely on this |
Logged In: YES In RE to tim_one:
On the countrary, my friend, and here's why:
This sentecnce does not say that whitespace will be
Neither does this one.
And not that one.
And that last one does not mention it either. In fact, there >>> ",2,".split(',')
['', '2', '']
>>> " 2 ".split()
['2'] This inconsistent behavior is not in line with how
I thought as much. However - it's would be Really easy for Cheers guys! |
Logged In: YES What new wording do you propose to be added? |
Logged In: YES Replacing the quoted line: """ If sep is not specified or is None, a different splitting |
Logged In: YES The prosposed wording is fine. If there are no objections or concerns, I'll apply it soon. |
Logged In: YES Brilliant, guys! Thanks again for a superb scripting language, and with Take care! |
Logged In: YES To me, the removal of whitespace at the ends (stripping) is >>> ',1,,2,'.split(',')
['', '1', '', '2', ''] If ' 1 2 '.split() were to return null strings at the beginning >>> ' 1 2 '.split(' ')
['', '1', '', '2', ''] Having said this, I also agree that the extra words proposed BUG?? In 2.2, splitting an empty or whitespace only string >>> ''.split()
[]
>>> ' '.split()
[] which is what I see as consistent with the rest of the no-null- |
Logged In: YES This should probably also be added to rsplit()? |
Logged In: YES I'm opening this again, since the docs still don't reflect from the docs: This is not true when maxsplit is given. Example: >>> " foo bar ".split(None)
['foo', 'bar']
>>> " foo bar ".split(None, 1)
['foo', 'bar '] Whitespace is obviously not stripping whitespace from the |
Logged In: YES *resubmission: grammar corrected* I'm opening this again, since the docs still don't reflect from the docs: This is not true when maxsplit is given. Example:
>>> " foo bar ".split(None)
['foo', 'bar']
>>> " foo bar ".split(None, 1)
['foo', 'bar '] Whitespace is obviously not stripped from the ends before |
I think the current wording is clear enough and that further attempts to specify corner cases will only make the docs harder to understand and less useful. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: