new string method in 2.5 (partition)
steve at holdenweb.com
Wed Sep 20 21:17:32 CEST 2006
Irmen de Jong wrote:
> Terry Reedy wrote:
>>"Bruno Desthuilliers" <bdesth.quelquechose at free.quelquepart.fr> wrote in
>>message news:4510425e$0$12250$636a55ce at news.free.fr...
>>>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 actual use
>>cases. Sometimes it replaces s.find or s.index instead of s.split. In
>>some cases, it is meant to be used within a loop. I was not involved and
>>so would refer you to the pydev discussions.
> While there is the functional aspect of the new partition method, I was
> wondering about the following /technical/ aspect:
> 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?
> I can imagine that the tuple type returned by partition is actually
> a special object that contains a few internal pointers into the
> original string to point at the locations of each substring.
> Although a quick type check of the result object revealed that
> it was just a regular tuple type, so I don't think the above is true...
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list