[Python-Dev] partition() (was: Remove str.find in 3.0?)

Phillip J. Eby pje at telecommunity.com
Tue Aug 30 20:44:44 CEST 2005


At 02:25 PM 8/30/2005 -0400, Raymond Hettinger wrote:
>That case should be handled with consecutive partitions:
>># keep everything after the second 'X'
>head, found, s = s.partition('X')
>head, found, s = s.partition('x')

Or:
 s=s.partition('X')[2].partition('X')[2]
which actually suggests a shorter, clearer way to do it:
 s = s.after('X').after('X')
And the corresponding 'before' method, of course, such that if sep in s:
 s.before(sep), sep, s.after(sep) == s.partition(sep)
Technically, these should probably be before_first and after_first, with 
the corresponding before_last and after_last corresponding to rpartition.


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /