[issue1123] split(None, maxsplit) does not strip whitespace correctly

2007-10-08 Thread Georg Brandl

Georg Brandl added the comment:

This should now be fixed in r58368.

--
nosy: +georg.brandl
resolution:  -> fixed
status: open -> closed

__
Tracker <[EMAIL PROTECTED]>

__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1123] split(None, maxsplit) does not strip whitespace correctly

2007-10-07 Thread Brett Cannon

Brett Cannon added the comment:

Re-opening as jafo was referring to the string module's function
implementation which is deprecated.  The real  issue is that the
built-in types docs are bad.

--
assignee: fdrake -> 
resolution: invalid -> 
status: closed -> open
versions: +Python 2.6

__
Tracker <[EMAIL PROTECTED]>

__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1123] split(None, maxsplit) does not strip whitespace correctly

2007-09-18 Thread Nir Soffer

Nir Soffer added the comment:

I quoted str.split docs:

- http://docs.python.org/lib/string-methods.html
- http://docs.python.org/dev/library/stdtypes.html
- http://docs.python.org/dev/3.0/library/stdtypes.html

string.split doc does it explain this:

>>> ' a b '.split(None, 1)
['a', 'b ']
>>> ' a b '.split(None, 2)
['a', 'b']

.split method docs is more clear and describe this in a very simple way. 

This is a better description of the current behavior:

"If sep is not specified or is None, a different splitting algorithm 
is applied. First, whitespace characters (spaces, tabs, newlines, 
returns, and formfeeds) are stripped from the start of the string. Then, 
words are separated by arbitrary length strings of whitespace 
characters. Consecutive whitespace delimiters are treated as a single 
delimiter ("' 1 \t 2 \n 3 '.split()" returns "['1', '2', '3']").

If maxsplit is nonzero, at most maxsplit number of splits occur, and 
the remainder of the string is returned as the final element of the 
list, unless it is empty. Splitting an empty string or a string 
consisting of just whitespace returns an empty list."

__
Tracker <[EMAIL PROTECTED]>

__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1123] split(None, maxsplit) does not strip whitespace correctly

2007-09-18 Thread Sean Reifschneider

Sean Reifschneider added the comment:

In looking at the current documentation:

http://docs.python.org/dev/library/string.html#string.split

I don't see the wording the original poster mentions.  The current
documentation of the separator is clear and reasonable.  I'm going to
call this closed, unless someone can suggest specific wording changes to
the document let's call this done.

--
resolution:  -> invalid
status: open -> closed

__
Tracker <[EMAIL PROTECTED]>

__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1123] split(None, maxsplit) does not strip whitespace correctly

2007-09-18 Thread Brett Cannon

Brett Cannon added the comment:

The algorithm is actually kind of odd::

  >>> " a b".split(None, 0)
  ['a b']
  >>> "a b ".split(None, 0)
  ['a b ']
  >>> "a b ".split(None, 1)
  ['a', 'b ']

So trailing whitespace on the original string is stripped only if the
number of splits is great enough to lead to a possible split past the
last element.  But leading whitespace is always removed.

Basically the algorithm stops looking for whitespace once it has
encountered maxsplit instances of contiguous whitespace plus leading
whitespace.

--
nosy: +brett.cannon

__
Tracker <[EMAIL PROTECTED]>

__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1123] split(None, maxsplit) does not strip whitespace correctly

2007-09-17 Thread Sean Reifschneider

Sean Reifschneider added the comment:

I believe this is just a place where the documentation could be cleared
up.  Seems to me the confusion is from the document saying
(paraphrased): "white space is removed from both ends".

Perhaps it should say something like "runs of 1 or more whitespace are
collapsed (up to the maximum split), and then split on" or simply "split
on runs of 1 or more whitespace.  In other words, 3 spaces together
would be treated as a single split-point instead of 3 0-length fields
separated by spaces."

So, in the first example provided by "nirs" in this issue, "both ends"
refers to both the left and right side of "k:".  Since maxsplit is 1,
the second part (v) is left untouched.  This is the intended operation.

This is a documentation bug, not a library bug.

Fred: Thoughts on wording?

--
assignee:  -> fdrake
components: +Documentation -Library (Lib)
nosy: +fdrake, jafo
priority:  -> low

__
Tracker <[EMAIL PROTECTED]>

__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1123] split(None, maxsplit) does not strip whitespace correctly

2007-09-11 Thread Nir Soffer

Nir Soffer added the comment:

There is a problem only when maxsplit is smaller than the available 
splits. In other cases, the docs and the behavior match.

__
Tracker <[EMAIL PROTECTED]>

__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1123] split(None, maxsplit) does not strip whitespace correctly

2007-09-10 Thread Fredrik Lundh

Fredrik Lundh added the comment:

But wasn't your complaint that the implementation didn't match the
documentation?

As I said, the *implementation* treats "runs of whitespace" as
separators, except for whitespace at the beginning or end (or in other
words, it never returns empty strings).  That matches the documentation,
except for the "first" in "first, whitespace characters are stripped
from both ends".   As far as I can tell, the documentation has never
matched the implementation here.

__
Tracker <[EMAIL PROTECTED]>

__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1123] split(None, maxsplit) does not strip whitespace correctly

2007-09-10 Thread Nir Soffer

Nir Soffer added the comment:

I did not look into the source, but obviously there is striping of 
leading and trailing whitespace. 

When you specify a separator you get:
>>> '  '.split(' ')
['', '', '']

>>> '  a  b  '.split('  ')
['', 'a', 'b', '']

So one would expect to get this without striping:
>>> '  a  b  '.split()
['', 'a', 'b', '']

But you get this:
>>> '  a  b  '.split()
['a', 'b']

So the documentation is correct.

__
Tracker <[EMAIL PROTECTED]>

__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1123] split(None, maxsplit) does not strip whitespace correctly

2007-09-10 Thread Fredrik Lundh

Fredrik Lundh added the comment:

Looks like a *documentation* bug to me; at the implementation level,
None just means "no empty parts, treat runs of whitespace as separators".

--
nosy: +effbot

__
Tracker <[EMAIL PROTECTED]>

__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1123] split(None, maxsplit) does not strip whitespace correctly

2007-09-07 Thread Guido van Rossum

Changes by Guido van Rossum:


__
Tracker <[EMAIL PROTECTED]>

__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1123] split(None, maxsplit) does not strip whitespace correctly

2007-09-07 Thread Guido van Rossum

Changes by Guido van Rossum:


__
Tracker <[EMAIL PROTECTED]>

__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1123] split(None, maxsplit) does not strip whitespace correctly

2007-09-06 Thread Nir Soffer

Nir Soffer added the comment:

set type

--
type:  -> behavior

__
Tracker <[EMAIL PROTECTED]>

__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1123] split(None, maxsplit) does not strip whitespace correctly

2007-09-06 Thread Nir Soffer

Nir Soffer added the comment:

typo in the title

--
title: split(None, maxplit) does not strip whitespace correctly -> split(None, 
maxsplit) does not strip whitespace correctly

__
Tracker <[EMAIL PROTECTED]>

__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com