[Python-3000] Automatically invoking str() in str.join()

Tim Peters tim.peters at gmail.com
Sat Apr 29 08:07:30 CEST 2006


[Fredrik]
>>> I don't think anyone on this list can take the "but if there's more than
>>> one argument, *I* am going to be confused" argument seriously.

[Tim]
>> Then you don't remember that the order of arguments here _was_ a
>> frequent confusion in the old days.

[Fredrik]
> nope.
>
> any pointers ?

Let's see.  Should I watch a movie now, or search pre-string-method
archives for quotes nobody really cares about?  While I think about
that ;-), you could look in _this_ thread for:

[Aahz]
> I never have gotten mixed up about the order of arguments since switching
> to ''.join(l).

[Tim H, replying to the Aahz quote]
> Me too

[Barry W]
> But hey, yeah, a join() builtin would be fine if it took the string arg first

[Alex M]
> I think I would prefer a signature of:   join(seq, joiner='')

[Barry W, replying to the Alex M quote]
> Except that I think it would be a mistake to have that and keep
> the .join() method on strings because that would increase the confusion
> in the argument order.

OK, the movie sucked.  Two of my favorites, which I remembered but
took damn near forever to find:

http://mail.python.org/pipermail/python-list/2001-March/031744.html

    ...
    from string import join

    l = join(';', ['a','b','c']) # thanks, this is clear and obvious

    Please o' gods of python, do not deprecate the clean and obvious syntax
    that is found in the string module.

Of course the joke is that he got the "clear and obvious" order backwards.

My other favorite showed up in a proposed PEP:

http://mail.python.org/pipermail/python-list/2001-June/048258.html

    ...

    It is *not* suggested that file objects take on this aspect of print
    behavior, such as by implementing a method print(self, items,
    print_newline=1, softsep=' ', linesep='\n'), and if not implemented,
    falling back to stream.write(string.join(' ', map(str, items)) + "\n").

And the arguments are backwards there too.

If you don't remember these confusions, I think it should suffice to
remind that Perl's join() does take the separator first (which is
essentially forced in Perl, given its odd LIST syntax):

    http://perldoc.perl.org/functions/join.html

While I don't know for sure, I always assumed that was the true source
of most of the relevant "how come my code doesn't work?!" complaints
on comp.lang.python before string methods were introduced.

This wasn't as frequent as posts showing confusions over the order of
arguments to (say) re.search, because _trying_ to do
string.join(a_string, a_list) raised an exception immediately,
although it wasn't a particularly clear exception.  If you try the old
string.join() code under a current Python, the exception message is
better than it was then, but would still be baffling to many newbies:

TypeError: can only concatenate list (not "str") to list


More information about the Python-3000 mailing list