[Python-Dev] str.join, string.join

Christian Tismer tismer@tismer.com
Tue, 11 Feb 2003 19:04:57 +0100

Hi Tim, pydev,

while fighting this conditional super thread,
I stumbled over something about "".join, as
it was used as an argument for reading LtoR.

Citing A. Koenig and Ahz: """

Aahz> Many people (including me) think it's *NOT* Pythonic.

If I were trying to make code easy to understand for inexperienced
programmers, I would write str.join(',', lines) instead of

I have two observations:

Through introduction of strings as class-like
objects, new calling patterns are generated.

Unfortunately, this is the opposite as in
the string module:
    str.join(',', lines)     # vs.
    string.join(lines, ',')

What is now pythonic. Was it (a posteriori) a
mistake to add join as a method to strings, since
it creates a calling pattern that is incompatible
with the string function?

Side remark: This error message is confusing:
 >>> str.join(" ")
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
TypeError: join() takes exactly one argument (0 given)

Well, the method is probably not well suited to be called
by the class, only (expecting to be a method, always).
But now it exists.

Given the str "class", we could use it to make
the string module absolutely redundant, since
we can put all string constants into str now.
So we would be able to use
     str.digits  # instead of

Trying to make sense of 1) and 2), I get into
trouble because of the inconsistent join issue.

What is the long-term way to make this pythonic
Should "".join be dropped in favor of a class
method which reads like the old string.join?
Or should it be kept like today, exist as
"".join(stuff) and str.join("", stuff), and
string.join becomes deprecated?

ciao - chris

Christian Tismer             :^)   <mailto:tismer@tismer.com>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a     :    *Starship* http://starship.python.net/
14109 Berlin                 :     PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34  home +49 30 802 86 56  pager +49 173 24 18 776
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
      whom do you want to sponsor today?   http://www.stackless.com/