Re: [Python-Dev] partition() (was: Remove str.find in 3.0?)

Phillip J. Eby wrote:
+1 for partition().
Looks like I'm getting seriously outvoted here ... Still, as I said I don't think the name is overly important until the idea has been accepted anyway. How long did we go with people in favour of "resource manager" until "context manager" came up? Of course, if I (or someone else) can't come up with an obviously better name, partition() will win by default. I don't think it's a *bad* name - just don't think it's a particularly *obvious* name. I think that one of the things I have against it is that most times I type it, I get a typo. If this function is accepted, I think it will (and should!) become one of the most used string functions around. As such, the name should be *very* easy to type. Tim Delaney

Delaney, Timothy (Tim) wrote:
I think that one of the things I have against it is that most times I type it, I get a typo. If this function is accepted, I think it will (and should!) become one of the most used string functions around. As such, the name should be *very* easy to type.
FWIW, the analogy with quicksort convinced me that partition is a good name, even though I'm a terirlbe tpyist. I'm a pretty good proofreader, though. ;-) Shane

On Tue, Aug 30, 2005, Delaney, Timothy (Tim) wrote:
Looks like I'm getting seriously outvoted here ... Still, as I said I don't think the name is overly important until the idea has been accepted anyway. How long did we go with people in favour of "resource manager" until "context manager" came up?
In that case, though, it was more, "Well, I'm not that happy with 'context manager', but there doesn't seem to be anything better." This time, it's closer to, "That's a good name for the concept, yup." As you say, if someone comes up with a clearly better name, it likely will win; however, partition has been blessed by enough people that it's not worth putting much effort into finding anything better.
Of course, if I (or someone else) can't come up with an obviously better name, partition() will win by default. I don't think it's a *bad* name - just don't think it's a particularly *obvious* name.
It's at least as obvious as translate(). <shrug> -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ The way to build large Python applications is to componentize and loosely-couple the hell out of everything.

"Delaney, Timothy (Tim)" <tdelaney@avaya.com> writes:
Phillip J. Eby wrote:
+1 for partition().
Looks like I'm getting seriously outvoted here ... Still, as I said I don't think the name is overly important until the idea has been accepted anyway. How long did we go with people in favour of "resource manager" until "context manager" came up?
Certainly no longer than until I got up the morning after the discussion started :) partition() works for me. It's not perfect, but it'll do. The idea works for me rather more; it even simplifies the if s.startswith(prefix): t = s[len(prefix):] ... idiom I occasionally wince at. Cheers, mwh -- Gullible editorial staff continues to post links to any and all articles that vaguely criticize Linux in any way. -- Reason #4 for quitting slashdot today, from http://www.cs.washington.edu/homes/klee/misc/slashdot.html

Michael Hudson wrote:
partition() works for me. It's not perfect, but it'll do. The idea works for me rather more; it even simplifies the
if s.startswith(prefix): t = s[len(prefix):] ...
How would you do it? Something like: head, found, tail = s.partition(prefix) if found and not head: ... I guess I agree that's an improvement - only a slight one, though. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.blogspot.com

Nick Coghlan <ncoghlan@gmail.com> writes:
Michael Hudson wrote:
partition() works for me. It's not perfect, but it'll do. The idea works for me rather more; it even simplifies the
if s.startswith(prefix): t = s[len(prefix):] ...
How would you do it? Something like:
head, found, tail = s.partition(prefix) if found and not head: ...
I guess I agree that's an improvement - only a slight one, though.
Yes. I seem to fairly often[1] do this with prefix as a literal so only having to mention it once would be a win for me. Cheers, mwh [1] But not often enough to have defined a function to do this job, it seems. -- <teratorn> I must be missing something. It is not possible to be this stupid. <Yhg1s> you don't meet a lot of actual people, do you?

Delaney, Timothy (Tim) wrote:
Of course, if I (or someone else) can't come up with an obviously better name, partition() will win by default. I don't think it's a *bad* name - just don't think it's a particularly *obvious* name.
What about simply "str.parts" and "str.rparts"? That is, rather than splitting the string on a separator, we are breaking it into parts - the part before the separator, the separator itself, and the part after the separator. Same concept as 'partition', just a shorter method name. Another option would be simply "str.part()" and "str.rpart()". Then you could think of it as an abbreviation of either 'partition' or 'parts' depending on your inclination.
I think that one of the things I have against it is that most times I type it, I get a typo. If this function is accepted, I think it will (and should!) become one of the most used string functions around. As such, the name should be *very* easy to type.
I've been typing 'partition' a lot lately at work, and Tim's right - typing this correctly is harder than you might think. It is very easy to only type the 'ti' in the middle once, so that you end up with 'partion'. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.blogspot.com

Nick Coghlan wrote:
Another option would be simply "str.part()" and "str.rpart()". Then you could think of it as an abbreviation of either 'partition' or 'parts' depending on your inclination.
I momentarily forgot that "part" is also a verb in its own right, with the right meaning, too (think "parting your hair" and "parting the Red Sea"). So call it +1 for str.part and str.rpart, and +0 for str.partition and str.rpartition. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.blogspot.com

(unlurking) Le mardi 30 août 2005 à 23:20 +1000, Nick Coghlan a écrit :
I momentarily forgot that "part" is also a verb in its own right, with the right meaning, too (think "parting your hair" and "parting the Red Sea").
"parts" sounds more obvious than the verb "part" which is little known to non-native English speakers (at least to me anyway). Just my 2 cents. Regards Antoine.

Concerning names for partition(), I immediately thought of break(). Unfortunately it's taken. So, how about snap()? head, sep, tail = line.snap(':') -j

Jason Orendorff <jason.orendorff@gmail.com> wrote:
Concerning names for partition(), I immediately thought of break(). Unfortunately it's taken.
So, how about snap()?
I like .part()/.rpart() (or failing that, .parts()/.rparts()). But if you really want something short that's similar in meaning, there's also .cut(). Charles -- ----------------------------------------------------------------------- Charles Cazabon <python@discworld.dyndns.org> GPL'ed software available at: http://pyropus.ca/software/ -----------------------------------------------------------------------

Hey guys, don't get lost in random naming suggestions (cut, snap, part, parts, yada yada yada). Each of those is much less descriptive and provides less differentiation from other string methods. Saving a few characters is not worth introducing ambiguity. Also, the longer name provides a useful visual balance between the three assigned variables and the separator argument. As an extreme example, contrast the following: head, found, tail = s.p(separator) head, found, tail = s.partition(separator) The verb gets lost if it doesn't have visual weight. Also, for those suggesting alternate semantics (raising exceptions when the separator is not found), I challenge you to prove their worth by doing all the code transformations that I did. It is a remarkably informative exercise that quickly reveals that this alternative is dead-on-arrival. For the poster suggesting an optional length argument, I suggest writing out the revised method invariants. I think you'll find that it snarls them into incomprehensibility and makes the tool much more difficult to learn. Also, I recommend scanning my sample library code transformations to see if any of them would benefit from the length argument. I think you'll find that it comes up so infrequently and with such differing needs that it would be a mistake to bake this into the proposal. Raymond

On 30 aug 2005, at 17.11, Raymond Hettinger wrote:
Hey guys, don't get lost in random naming suggestions (cut, snap, part, parts, yada yada yada). Each of those is much less descriptive and provides less differentiation from other string methods. Saving a few characters is not worth introducing ambiguity.
Trisect would be pretty descriptive ... //Simon

Nick> I momentarily forgot that "part" is also a verb in its own right, Nick> with the right meaning, too (think "parting your hair" and Nick> "parting the Red Sea"). If I remember correctly from watching "The Ten Commandments" as a kid, I believe Charlton Heston only parted the Red Sea in one place... Skip

Nick> What about simply "str.parts" and "str.rparts"? -1 because "parts" is not a verb. When I see an attribute that is a noun I generally expect it to be a data attribute. Skip

I like partition() but maybe even better would be if strings supported slicing by string indices. key, sep, val = 'foo = 32'.partition('=') would be: key, val = 'foo = 32'[:'='], 'foo = 32'['=':] To me it feels very natural to extend Python's slices to string indices and would cover most of partition()'s use cases. The if sep: idiom of parition() could be solved by throwing an IndexError: e.g: _, sep, port = host.partition(':') if sep: try: int(port) except ValueError: becomes: try: port = host[':':] int(port) except IndexError: pass except ValueError: An advantage of using slices would be that you could specify both a beginning and ending string like this:
s 'http://192.168.12.22:8080' s['http://':':'] '192.168.12.22'
Sorry if this idea has already been discussed. -- mvh Björn

Nick Coghlan wrote:
Another option would be simply "str.part()" and "str.rpart()". Then you could think of it as an abbreviation of either 'partition' or 'parts' depending on your inclination.
Or simply as the verb 'part', which also makes sense! Also it's short and snappy, whereas 'partition' seems rather too long-winded for such a useful little function. -- Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg.ewing@canterbury.ac.nz +--------------------------------------+
participants (13)
-
Aahz
-
Antoine Pitrou
-
BJörn Lindqvist
-
Charles Cazabon
-
Delaney, Timothy (Tim)
-
Greg Ewing
-
Jason Orendorff
-
Michael Hudson
-
Nick Coghlan
-
Raymond Hettinger
-
Shane Hathaway
-
Simon Percivall
-
skip@pobox.com