Movatterモバイル変換


[0]ホーム

URL:


[Python-Dev] Proof of the pudding: str.partition()

Raymond Hettingerraymond.hettinger at verizon.net
Tue Aug 30 22:27:48 CEST 2005


[Fredrik Lundh]> it is, however, a bit worrying that you end up ignoring one or more> of the values in about 50% of your examples... It drops to about 25% when you skip the ones that don't care about thefound/not-found field:> > !     _, sep, port = host.partition(':')> > !             head, sep, _ = path.rpartition('/')> > !                 line, _, _ = line.partition(';')  # strip> > !         pname, found, _ = pname.rpartition('.')> > !             line, _, _ = line.partition('#')> > !         filename, _, _ = filename.partition(chr(0))The remaining cases don't bug me much.  They clearly say, ignore theleft piece or ignore the right piece.  We could, of course, make theseclearer and more efficient by introducing more methods:      s.before(sep)  --> (left, sep)   s.after(sep)   --> (right, sep)   s.rbefore(sep) --> (left, sep)   s.r_after(sep) --> (right, sep)But who wants all of that?Raymond


More information about the Python-Devmailing list

[8]ページ先頭

©2009-2025 Movatter.jp