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
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
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
[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
[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
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
>> 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
> 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
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
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
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.
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
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
>>
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
"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
"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
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
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
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
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
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
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.
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
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?
--
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
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
26 matches
Mail list logo