[issue22360] Adding manually offset parameter to str/bytes split function
Christoph Wruck
report at bugs.python.org
Mon Sep 8 14:43:44 CEST 2014
Christoph Wruck added the comment:
Hi Steven
exactly - you're right with this.
'spam--eggs--cheese----toast'.split('-', offset=1)
--> ['spam', '-eggs', '-cheese', '-', '-toast']
'spam--eggs--cheese--toast'.split('-', offset=8)
--> ['spam', '-eggs--cheese', '-toast']
Okay - the name "offset" might be an unfortunate choice and you are right that this could be hard to understand for a caller.
One more examples:
The following removes all escape signs to process the octal escape sequences in a second way if the first three characters are digits.
'spam\\055\\\\055-eggs-\\\\rest'.split('\\', offset=1)
--> ['spam', '055', '\\055-eggs-', '\\rest']
# could speed up the split built-in func if a caller knows that every chunk is 3 chars long?
'tic-tac-toe'.split('-', offset=3)
A caller could use the offset parameter to keep all separators between
the last found and offset if it's a part of a chunk. Or if he awaiting a separator followed by itself which should be keeped - in doubt with the same length of separator.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22360>
_______________________________________
More information about the Python-bugs-list
mailing list