string.join() syntax quirky?

Quinn Dunkan quinn at regurgitate.ugcs.caltech.edu
Sun Nov 25 17:56:05 EST 2001


On 23 Nov 2001 10:12:06 -0500, François Pinard <pinard at iro.umontreal.ca> wrote:
>[Marcin 'Qrczak' Kowalczyk]
>
>> Thu, 22 Nov 2001 18:51:07 GMT, Erik Johnson <ejohnso9 at earthlink.net> pisze:
>
>> > is there a logical reason why it was implemented as a string method
>> > rather than a list method?
>
>> > Does it seem backwards to you or does it make intuitive sense to you?
>
>> It seems backwards for me - the sequence is more important than the
>> separator - but I wouldn't treat it as a list method either.  More as
>> a global function.
>
>You assertion about the sequence being much more important than the separator
>is supported by Python designers of the string module.  The separator
>is indeed optional in string.join(), and then implied to a single space.
>It always looked ugly to me that it became mandatory in the new syntax, and
>this ugliness always got me to think that there is something fundamentally
>wrong with it, even if many clever people torn their mind at finding it nice.

I was doubtful about this when it was first introduced, but was quieted by the
large amounts of rationalization being generated.  "I'll get used to it." I
thought.  "No big deal."

But now I'm more convinced it was a bad decision, for me at lesat.  That's
because while programming in real life I *still* type "a.join('')" and
"':'.split(s)".  It's hard to spot the error later because "' '.join(a)" still
looks weird to me, just as weird (or just as "normal") as "':'.split(s)".

Both mistakes produce plausible output that will only cause something to choke
a ways down the road.

>Maybe that a mere built-in function "join(SEQUENCE)" should exist,
>equivalent to "string.join(SEQUENCE)", a kind of "' '.join(SEQUENCE)"
>where ' ' would have been made optional, and dropped. :-)

I've decided to do what I should have from the beginning: always use
string.join.  I didn't want to because it seemed silly to import a whole
module for one function, and as long as I'm using Official String Methods for
everything else I should use them for joins too.



More information about the Python-list mailing list