[docs] re.split suggestion

Bill.Melvin at esc.edu Bill.Melvin at esc.edu
Tue Oct 22 22:11:16 CEST 2013


Hi Docs,

I just tripped myself up with the maxsplit parameter to re.split while 
parsing SPF records ...

>>> max = 2
>>> re.split(':','ip6:fe80:dead:beef:cafe::36',maxsplit=max)
['ip6', 'fe80', 'dead:beef:cafe::36']
>>>
>>> max = 1
>>> re.split(':','ip6:fe80:dead:beef:cafe::36',maxsplit=max)
['ip6', 'fe80:dead:beef:cafe::36']

Re-re-re-reading the docs I see now that maxsplit is in fact the maximum 
number of _splits_ that occur not the number of fields that result.

FWIW I am relatively new to Python so my terminology will be off but does 
a patch something like the appended make sense?

tnx,

/b

http://docs.python.org/n.m/_sources/library/re.txt

$ diff -uw re.orig re.txt
--- re.orig     2013-10-22 16:01:50.876739700 -0400
+++ re.txt      2013-10-22 16:02:39.752052500 -0400
@@ -589,7 +589,7 @@
    Split *string* by the occurrences of *pattern*.  If capturing 
parentheses are
    used in *pattern*, then the text of all groups in the pattern are also 
returned
    as part of the resulting list. If *maxsplit* is nonzero, at most 
*maxsplit*
-   splits occur, and the remainder of the string is returned as the final 
element
+   splits occur, creating a list *maxsplit+1* elements in length with the 
remainder of the string is returned as the final element
    of the list. ::

       >>> re.split('\W+', 'Words, words, words.')
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20131022/3acb1fd0/attachment-0001.html>


More information about the docs mailing list