new string method in 2.5 (partition)
Tim Chase
python.list at tim.thechases.com
Tue Sep 19 15:28:30 EDT 2006
> But you raise a good point. Notice this:
>
> >>> s = 'hello, world, how are you'
>
> >>> s.split(',')
> ['hello', ' world', ' how are you']
>
> >>> s.partition(',')
> ('hello', ',', ' world, how are you')
>
> split will return all substrings. partition (and rpartition) only return
> the substrings before and after the first occurrence of the argument.
The split()/rsplit() functions do take an optional argument for
the maximum number of splits to make, just FYI...
>>> help("".split)
Help on built-in function split:
split(...)
S.split([sep [,maxsplit]]) -> list of strings
Return a list of the words in the string S, using sep as the
delimiter string. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator.
(as I use this on a regular basis when mashing up various text
files in a data conversion process)
-tkc
More information about the Python-list
mailing list