Movatterモバイル変換
[0]ホーム
[Python-Dev] partition() (was: Remove str.find in 3.0?)
Pierre Barbier de Reuillepierre.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 rersep = 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 regularexpressions: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 ReuilleINRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAPBotanique et Bio-informatique de l'Architecture des PlantesTA40/PSII, Boulevard de la Lironde34398 MONTPELLIER CEDEX 5, Francetel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68
More information about the Python-Devmailing list
[8]ページ先頭