new string method in 2.5 (partition)

2006-09-19 Thread John Salerno
Forgive my excitement, especially if you are already aware of this, but this seems like the kind of feature that is easily overlooked (yet could be very useful): Both 8-bit and Unicode strings have new partition(sep) and rpartition(sep) methods that simplify a common use case. The find(S) meth

Re: new string method in 2.5 (partition)

2006-09-19 Thread metaperl
sweet thanks for the heads up. John Salerno wrote: > Forgive my excitement, especially if you are already aware of this, but > this seems like the kind of feature that is easily overlooked (yet could > be very useful): > > > Both 8-bit and Unicode strings have new partition(sep) and > rpartition(s

Re: new string method in 2.5 (partition)

2006-09-19 Thread [EMAIL PROTECTED]
I'm confused. What's the difference between this and string.split? John Salerno wrote: > Forgive my excitement, especially if you are already aware of this, but > this seems like the kind of feature that is easily overlooked (yet could > be very useful): > > > Both 8-bit and Unicode strings have n

Re: new string method in 2.5 (partition)

2006-09-19 Thread Lawrence Oluyede
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > What's the difference between this and string.split? >>> ('http://www.python.org').partition('://') ('http', '://', 'www.python.org') >>> ('http://www.python.org').split('://') ['http', 'www.python.org'] -- Lawrence - http://www.oluyede.org/blog

Re: new string method in 2.5 (partition)

2006-09-19 Thread John Salerno
[EMAIL PROTECTED] wrote: > I'm confused. > What's the difference between this and string.split? >>> s = 'hello, world' >>> s.split(',') ['hello', ' world'] >>> s.partition(',') ('hello', ',', ' world') split returns a list of the substrings on either side of the specified argument. partit

Re: new string method in 2.5 (partition)

2006-09-19 Thread Bruno Desthuilliers
John Salerno a écrit : > Forgive my excitement, especially if you are already aware of this, but > this seems like the kind of feature that is easily overlooked (yet could > be very useful): > > > Both 8-bit and Unicode strings have new partition(sep) and > rpartition(sep) methods that simplif

Re: new string method in 2.5 (partition)

2006-09-19 Thread Tim Chase
>> partition(sep) condenses this pattern into a single method >> call that returns a 3-tuple containing the substring before >> the separator, the separator itself, and the substring after >> the separator. If the separator isn't found, the first >> element of the tuple is the entire string and th

Re: new string method in 2.5 (partition)

2006-09-19 Thread Tim Chase
> 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 s

Re: new string method in 2.5 (partition)

2006-09-19 Thread John Salerno
Bruno Desthuilliers wrote: > Err... is it me being dumb, or is it a perfect use case for str.split ? Hmm, I suppose you could get nearly the same functionality as using split(':', 1), but with partition you also get the separator returned as well. > There are IMVHO much exciting new features

Re: new string method in 2.5 (partition)

2006-09-19 Thread Thomas Heller
John Salerno schrieb: > Bruno Desthuilliers wrote: > >> Err... is it me being dumb, or is it a perfect use case for str.split ? > > Hmm, I suppose you could get nearly the same functionality as using > split(':', 1), but with partition you also get the separator returned as > well. Well, x.spl

Re: new string method in 2.5 (partition)

2006-09-19 Thread George Sakkis
Bruno Desthuilliers wrote: > I must definitively be dumb, but so far I fail to see how it's better > than split and rsplit: I fail to see it too. What's the point of returning the separator since the caller passes it anyway* ? George * unless the separator can be a regex, but I don't think so.

Re: new string method in 2.5 (partition)

2006-09-19 Thread Larry Bates
John Salerno wrote: > Bruno Desthuilliers wrote: > >> Err... is it me being dumb, or is it a perfect use case for str.split ? > > Hmm, I suppose you could get nearly the same functionality as using > split(':', 1), but with partition you also get the separator returned as > well. > >> There are

Re: new string method in 2.5 (partition)

2006-09-19 Thread John Salerno
Larry Bates wrote: > John Salerno wrote: >> Bruno Desthuilliers wrote: >> >>> Err... is it me being dumb, or is it a perfect use case for str.split ? >> Hmm, I suppose you could get nearly the same functionality as using >> split(':', 1), but with partition you also get the separator returned as >>

Re: new string method in 2.5 (partition)

2006-09-19 Thread Jack Diederich
On Tue, Sep 19, 2006 at 07:23:50PM +, John Salerno wrote: > Bruno Desthuilliers wrote: > > > Err... is it me being dumb, or is it a perfect use case for str.split ? > > Hmm, I suppose you could get nearly the same functionality as using > split(':', 1), but with partition you also get the se

Re: new string method in 2.5 (partition)

2006-09-19 Thread Duncan Booth
"George Sakkis" <[EMAIL PROTECTED]> wrote: > Bruno Desthuilliers wrote: > >> I must definitively be dumb, but so far I fail to see how it's better >> than split and rsplit: > > I fail to see it too. What's the point of returning the separator since > the caller passes it anyway* ? > The separat

Re: new string method in 2.5 (partition)

2006-09-19 Thread Terry Reedy
"Bruno Desthuilliers" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >Err... is it me being dumb, or is it a perfect use case for str.split ? s.partition() was invented and its design settled on as a result of looking at some awkward constructions in the standard library and other

Re: new string method in 2.5 (partition)

2006-09-20 Thread MonkeeSage
s = "There should be one -- and preferably only one -- obvious way to do it".partition('only one') print s[0]+'more than one'+s[2] ;) Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list

Re: new string method in 2.5 (partition)

2006-09-20 Thread Irmen de Jong
Terry Reedy wrote: > "Bruno Desthuilliers" <[EMAIL PROTECTED]> wrote in > message news:[EMAIL PROTECTED] >> Err... is it me being dumb, or is it a perfect use case for str.split ? > > s.partition() was invented and its design settled on as a result of looking > at some awkward constructions in t

Re: new string method in 2.5 (partition)

2006-09-20 Thread Steve Holden
Irmen de Jong wrote: > Terry Reedy wrote: > >>"Bruno Desthuilliers" <[EMAIL PROTECTED]> wrote in >>message news:[EMAIL PROTECTED] >> >>>Err... is it me being dumb, or is it a perfect use case for str.split ? >> >>s.partition() was invented and its design settled on as a result of looking >>at so

Re: new string method in 2.5 (partition)

2006-09-20 Thread Bruno Desthuilliers
John Salerno a écrit : > Bruno Desthuilliers wrote: > >> Err... is it me being dumb, or is it a perfect use case for str.split ? > > > Hmm, I suppose you could get nearly the same functionality as using > split(':', 1), but with partition you also get the separator returned as > well. Well, y

Re: new string method in 2.5 (partition)

2006-09-20 Thread Gabriel Genellina
At Wednesday 20/9/2006 15:11, Irmen de Jong wrote: Because the result of partition is a non mutable tuple type containing three substrings of the original string, is it perhaps also the case that partition works without allocating extra memory for 3 new string objects and copying the substrings

Re: new string method in 2.5 (partition)

2006-09-20 Thread Irmen de Jong
Gabriel Genellina wrote: > Nope, a python string has both a length *and* a null terminator (for > ease of interfacing C routines, I guess) so you can't just share a > substring. Ofcourse, that makes perfect sense. Should have thought a little bit further myself :) --Irmen -- http://mail.

Re: new string method in 2.5 (partition)

2006-09-21 Thread Fredrik Lundh
Irmen de Jong wrote: > Because the result of partition is a non mutable tuple type containing > three substrings of the original string, is it perhaps also the case > that partition works without allocating extra memory for 3 new string > objects and copying the substrings into them? nope. the c

Re: new string method in 2.5 (partition)

2006-09-22 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Gabriel Genellina wrote: > ... a python string has both a length *and* a null terminator (for > ease of interfacing C routines ... How does that work for strings with embedded nulls? Or are the C routines simply fooled into seeing a truncated part of the string? --

Re: new string method in 2.5 (partition)

2006-09-22 Thread Duncan Booth
Lawrence D'Oliveiro <[EMAIL PROTECTED]> wrote: > In message <[EMAIL PROTECTED]>, Gabriel > Genellina wrote: > >> ... a python string has both a length *and* a null terminator (for >> ease of interfacing C routines ... > > How does that work for strings with embedded nulls? Or are the C routines

Re: new string method in 2.5 (partition)

2006-09-22 Thread Gabriel Genellina
At Friday 22/9/2006 04:53, Lawrence D'Oliveiro wrote: > ... a python string has both a length *and* a null terminator (for > ease of interfacing C routines ... How does that work for strings with embedded nulls? Or are the C routines simply fooled into seeing a truncated part of the string? T