New submission from Alan Grow <alangrow+pythonb...@gmail.com>:

If you split a string in a maximum of zero places, you should get the original 
string back. "".split(s,0) behaves this way. But re.split(r,s,0) performs an 
unlimited number of splits in this case.

To get an unlimited number of splits, "".split(s,-1) is a sensible choice. But 
in this case re.split(r,s,-1) performs zero splits.

Where's the sense in this?

>>> import string, re
>>> string.split("foo bar baz"," ",0)
['foo bar baz']
>>> re.split("\s+","foo bar baz",0)
['foo', 'bar', 'baz']
>>> string.split("foo bar baz"," ",-1)
['foo', 'bar', 'baz']
>>> re.split("\s+","foo bar baz",-1)
['foo bar baz']

----------
components: Library (Lib)
messages: 147066
nosy: acg
priority: normal
severity: normal
status: open
title: re.split() should behave like string.split() for maxsplit=0 and 
maxsplit=-1
type: behavior
versions: Python 2.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13346>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to