[Python-Dev] partition() (was: Remove str.find in 3.0?)
Pierre Barbier de Reuille
pierre.barbier at cirad.fr
Tue Aug 30 17:01:36 CEST 2005
Eric Nieuwland a écrit :
> I have some use cases with:
> cut_at = some_str.find(sep)
> head, tail = some_str[:cut_at], some_str[cut_at:]
> and:
> cut_at = some_str.find(sep)
> head, tail = some_str[:cut_at], some_str[cut_at+offset:] # offset !=
> len(sep)
>
> So if partition() [or whatever it'll be called] could have an optional
> second argument that defines the width of the 'cut' made, I would be
> helped enormously. The default for this second argument would be
> len(sep), to preserve the current proposal.
Well, IMO, your example is much better written:
import re
rsep = re.compile(sep + '.'*offset)
lst = re.split(resp, some_str, 1)
head = lst[0]
tail = lst[1]
Or you want to have some "partition" method which accept regular
expressions:
head, sep, tail = some_str.partition(re.compile(sep+'.'*offset))
>
> --eric
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/pierre.barbier%40cirad.fr
>
--
Pierre Barbier de Reuille
INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde
34398 MONTPELLIER CEDEX 5, France
tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68
More information about the Python-Dev
mailing list