[Python-Dev] String methods... finally
tim_one at email.msn.com
Sun Jun 13 21:34:57 CEST 1999
> >>>>> "TP" == Tim Peters <tim_one at email.msn.com> writes:
> TP> Same here, except as a method we've got it twice backwards
> TP> <wink>: it should be a string method, but a method of the
> TP> *separator*:
> TP> sep.join(seq)
> TP> same as
> | convert each elt in seq to a string of the same flavor as
> | sep, then paste the converted strings together with sep
> | between adjacent elements
> TP> So
> TP> " ".join(list)
> TP> delivers the same result as today's
> TP> string.join(map(str, list), " ")
> TP> and
> TP> L" ".join(list)
> TP> does much the same tomorrow but delivers a Unicode string (or
> TP> is the "L" for Lundh string <wink>?).
> TP> It looks odd at first, but the more I play with it the more I
> TP> think it's "the right thing" to do
Barry, did it ever occur to you to that this fancy Emacs quoting is pig ugly
[Barry A. Warsaw]
> At first glance, I like this proposal a lot.
That's a bit scary -- even I didn't like it at first glance. It kept
growing on me, though, especially after a trivial naming trick:
space, tab, null = ' ', '\t', ''
sentence = space.join(list)
table = tab.join(list)
squashed = null.join(list)
That's so beautifully self-descriptive I cried! Well, I actually jerked my
leg and stubbed my little toe badly, but it's healing nicely, thank you.
Note the naturalness too of creating zippier bound method objects for the
kinds of join you're doing most often:
spacejoin = ' '.join
tabjoin = '\t'.join
etc. I still like it more the more I play with it.
> I'd be happy to code it up if David'll stop throwing those rocks.
David warmed up to it in pvt email (his first response was the expected
+ David may want C.join(T) generalized to other classes C and argument types
T. So far my response to all such generalizations has been "wacky!" <wink>,
but I don't think that bears one way or t'other on whether
StringType.join(SequenceType) makes good sense on its own.
+ string.join(seq) doesn't currently convert seq elements to string type,
and in my vision it would. At least three of us admit to mapping str across
seq anyway before calling string.join, and I think it would be a nice
I think there's no confusion because there's nothing sensible
string.join *could* do with a non-string seq element other than
convert it to string. The primary effect of string.join griping
about a non-string seq element today is that my
if not ok:
sys.__stdout__.write("not ok, args are " + string.join(args) + "\n")
debugging output blows up instead of being helpful <0.8 wink>.
If Guido is opposed to being helpful, though <wink>, the auto-convert bit
> Whether or not they hit me, they still hurt <snif> :)
I know they do, Barry. That's why I never throw rocks at you. If you like,
I'll have a word with David's ISP.
reproduce-ly y'rs - tim
More information about the Python-Dev