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

2005-09-01 Thread Josiah Carlson
Greg Ewing [EMAIL PROTECTED] wrote: Josiah Carlson wrote: A bit of free thought brings me to the (half-baked) idea that if string methods accepted any object which conformed to the buffer interface; mmap, buffer, array, ... instances could gain all of the really convenient methods

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

2005-09-01 Thread Nick Coghlan
Charles Cazabon wrote: also, a Boolean positional argument is a really poor clue about its meaning, and it's easy to misremember the sense reversed. I totally agree. I therefore borrowed the time machine and modified my proposal to suggest it should be a keyword argument, not a positional

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

2005-09-01 Thread Raymond Hettinger
[Steve Holden] The collective brainpower that's been exercised on this one enhancement already must be phenomenal, but the proposal still isn't perfect. Sure it is :-) It was never intended to replace all string parsing functions, existing or contemplated. We still have str.index() so

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

2005-09-01 Thread William Trenker
On 9/1/05, Greg Ewing [EMAIL PROTECTED] wrote: LD Gus Landis wrote: .piece() can be both a verb and a noun Er, pardon? I don't think I've ever heard 'piece' used as a verb in English. Can you supply an example sentence? - assemble: make by putting pieces together; She pieced a quilt -

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

2005-08-31 Thread Fredrik Lundh
Ron Adam wrote: I'm not familiar with piece, but it occurred to me it might be useful to get attributes groups in some way. My first (passing) thought was to do... host, port = host.partition(':').(head, sep) Where that would be short calling a method to return them: host, port

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

2005-08-31 Thread Michael Chermside
Raymond's original definition for partition() did NOT support any of the following: (*) Regular Expressions (*) Ways to generate just 1 or 2 of the 3 values if some are not going to be used (*) Clever use of indices to avoid copying strings (*) Behind-the-scenes tricks to allow

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

2005-08-31 Thread skip
You can do both: make partition() return a sequence with attributes, similar to os.stat(). However, I would call the attributes before, sep, and after. Terry One could see that as a special-case back-compatibility kludge Terry that maybe should disappear in 3.0. Back

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

2005-08-31 Thread Phillip J. Eby
At 04:55 AM 8/31/2005 -0700, Michael Chermside wrote: Raymond's original definition for partition() did NOT support any of the following: (*) Regular Expressions This can be orthogonally added to the 're' module, and definitely should not be part of the string method. (*) Ways to

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

2005-08-31 Thread Fredrik Lundh
Phillip J. Eby wrote: Yep, subscripting and slicing are more than adequate to handle *all* of those use cases, even the ones that some people have been jumping through odd hoops to express: before = x.partition(sep)[0] found = x.partition(sep)[1] after = x.partition(sep)[2]

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

2005-08-31 Thread Charles Cazabon
Michael Chermside [EMAIL PROTECTED] wrote: (*) An rpartition() function that searches from the right ...except that I understand why he included it and am convinced by the arguments (use cases can be demonstrated and people would expect it to be there and complain if it weren't). I

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

2005-08-31 Thread Guido van Rossum
On 8/31/05, Charles Cazabon [EMAIL PROTECTED] wrote: I would think that perhaps an optional second argument to the method that controls whether it searches from the start (default) or end of the string might be nicer than having two separate methods, even though that would lose parallelism

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

2005-08-31 Thread Terry Reedy
[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] You can do both: make partition() return a sequence with attributes, similar to os.stat(). However, I would call the attributes before, sep, and after. Terry One could see that as a special-case

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

2005-08-31 Thread Charles Cazabon
Guido van Rossum [EMAIL PROTECTED] wrote: On 8/31/05, Charles Cazabon [EMAIL PROTECTED] wrote: While I'm at it, why not propose that for py3k that .rfind/.rindex/.rjust/.rsplit disappear, and .find/.index/.just/.split grow an optional fromright (or equivalent) optional keyword argument?

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

2005-08-31 Thread Jim Jewett
Michael Chermside wrote (but I reordered): Simplicity and elegence are two of the reasons that this is such an excellent proposal, let's not lose them. Raymond's original definition for partition() did NOT support any of the following: (*) Regular Expressions While this is obviously more

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

2005-08-31 Thread Bill Janssen
(*) Regular Expressions This can be orthogonally added to the 're' module, and definitely should not be part of the string method. Sounds right to me, and it *should* be orthogonally added to the 're' module coincidentally simultaneously with the change to the string object :-). I have

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

2005-08-31 Thread Reinhold Birkenfeld
Bill Janssen wrote: (*) Regular Expressions This can be orthogonally added to the 're' module, and definitely should not be part of the string method. Sounds right to me, and it *should* be orthogonally added to the 're' module coincidentally simultaneously with the change to the

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

2005-08-31 Thread Steve Holden
Fredrik Lundh wrote: Phillip J. Eby wrote: Yep, subscripting and slicing are more than adequate to handle *all* of those use cases, even the ones that some people have been jumping through odd hoops to express: before = x.partition(sep)[0] found = x.partition(sep)[1] after =

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

2005-08-31 Thread Josiah Carlson
Steve Holden [EMAIL PROTECTED] wrote: Fredrik Lundh wrote: the problem isn't the time it takes to unpack the return value, the problem is that it takes time to create the substrings that you don't need. Indeed, and therefore the performance of rpartition is likely to get worse as

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

2005-08-31 Thread Delaney, Timothy (Tim)
Fredrik Lundh wrote: the problem isn't the time it takes to unpack the return value, the problem is that it takes time to create the substrings that you don't need. I'm actually starting to think that this may be a good use case for views of strings i.e. rather than create 3 new strings,

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

2005-08-31 Thread LD \Gus\ Landis
Hi, FTR, I was not implying the $PIECE() was an answer at all, but only suggesting it as an alternative name to .partition(). .piece() can be both a verb and a noun as can .partition(), thus overcoming Nick's objection to a nounish thing doing the work of a verbish thing. Also, IIRC, I did say

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

2005-08-31 Thread Terry Reedy
for some use cases, a naive partition-based solution is going to be a lot slower than the old find+slice approach, no matter how you slice, index, or unpack the return value. The index+slice approach will still be available for such cases. I am sure we will see relative speed versus

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

2005-08-31 Thread Greg Ewing
Josiah Carlson wrote: A bit of free thought brings me to the (half-baked) idea that if string methods accepted any object which conformed to the buffer interface; mmap, buffer, array, ... instances could gain all of the really convenient methods that make strings the objects to use in many

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

2005-08-31 Thread Greg Ewing
LD Gus Landis wrote: .piece() can be both a verb and a noun Er, pardon? I don't think I've ever heard 'piece' used as a verb in English. Can you supply an example sentence? (And no, Piece, man! doesn't count. :-) Greg ___ Python-Dev mailing list

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

2005-08-31 Thread Shane Hathaway
Greg Ewing wrote: LD Gus Landis wrote: .piece() can be both a verb and a noun Er, pardon? I don't think I've ever heard 'piece' used as a verb in English. Can you supply an example sentence? After Java splintered in 20XX, diehard fans desperately pieced together the remaining fragments.

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

2005-08-31 Thread Stephen J. Turnbull
Greg == Greg Ewing [EMAIL PROTECTED] writes: Greg Er, pardon? I don't think I've ever heard 'piece' used as a Greg verb in English. Can you supply an example sentence? I'll let the reader piece it together. More closely related, I've heard/seen piece out used for task allocation (from

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

2005-08-30 Thread Benji York
Raymond Hettinger wrote: [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 the found/not-found field: ! _, sep, port =

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

2005-08-30 Thread Ron Adam
Benji York wrote: Raymond Hettinger wrote: [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 the found/not-found field: ! _, sep, port =

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

2005-08-30 Thread Delaney, Timothy (Tim)
Shane Hathaway wrote: Ron Adam wrote: For cases where single values are desired, attribues could work. Slicing: line = line.partition(';').head line = line.partition('#').head But it gets awkward as soon as you want more than one. sep, port =

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

2005-08-30 Thread Fredrik Lundh
Ron Adam wrote: For cases where single values are desired, attribues could work. Slicing: line = line.partition(';').head line = line.partition('#').head But it gets awkward as soon as you want more than one. sep, port = host.partition(':').head,

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

2005-08-30 Thread tony
I once wrote a similar method called cleave(). My use case involved a string-like class (Substr) whose instances could report their position in the original string. The re module wasn't preserving my class so I had to provide a different API. def cleave(self, pattern, start=0): return

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

2005-08-30 Thread Josiah Carlson
[EMAIL PROTECTED] wrote: Substr didn't copy as partition() will have to, won't many of uses of partition() end up being O(N^2)? Yes. But if you look at most cases provided for in the standard library, that isn't an issue. In the case where it becomes an issue, it is generally because a user

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

2005-08-30 Thread tony
Actually no. When str.parition() doesn't find the separator, you get s, '', ''. Yours would produce '', '', s. On not found, you would need to use start==end==len(s). You're right. Nevermind, then. I will say the same thing that I've said at least three times already (with a bit of an

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

2005-08-30 Thread Phillip J. Eby
At 01:05 AM 8/31/2005 +0200, Fredrik Lundh wrote: Ron Adam wrote: For cases where single values are desired, attribues could work. Slicing: line = line.partition(';').head line = line.partition('#').head But it gets awkward as soon as you want more than one.

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

2005-08-30 Thread Ron Adam
Fredrik Lundh wrote: Ron Adam wrote: For cases where single values are desired, attribues could work. Slicing: line = line.partition(';').head line = line.partition('#').head But it gets awkward as soon as you want more than one. sep, port = host.partition(':').head,

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

2005-08-30 Thread Terry Reedy
Shane Hathaway [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] You can do both: make partition() return a sequence with attributes, similar to os.stat(). However, I would call the attributes before, sep, and after. One could see that as a special-case back-compatibility kludge

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

2005-08-30 Thread Shane Hathaway
Terry Reedy wrote: Shane Hathaway [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] You can do both: make partition() return a sequence with attributes, similar to os.stat(). However, I would call the attributes before, sep, and after. One could see that as a special-case

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

2005-08-29 Thread Josiah Carlson
Raymond Hettinger [EMAIL PROTECTED] wrote: As promised, here is a full set of real-world comparative code transformations using str.partition(). The patch isn't intended to be applied; rather, it is here to test/demonstrate whether the new construct offers benefits under a variety of use