For review: PEP 308 - If-then-else expression

Christian Tismer tismer at tismer.com
Mon Feb 10 22:02:06 EST 2003


Andrew Koenig wrote:
>>>Then I wonder why do people think that the following snippet is pythonic in 
>>>any (reasonable) way:
> 
> 
>>>','.join(lines)
> 
> 
> 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
> ','.join(lines).

Great idea, IMHO!
Here, the union of types and classes really shows
its benefits: Having join as a class method sounds
pretty cool.

I think this is the time to add all the string constants
which have been in the string module to the str type/class.
This would make the string module *really* obsolete.
Example:
str.uppercase should act like sring.uppercase.

A look at Python 2.2.2:

 >>> str.join(" ",["a", "b"])
'a b'

already works.
It still smells a little weird, though, since the
string module had its parameters in a different order.
So maybe " ".join was somewhat logical, but not a very
good decision, after all.
But at that time, nobody ever expected that strings
would be like a class, in near future.

Something is strange, still:

 >>> 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).

Back to the issue.
" ".join(seq) is equivalent to
   str.join(" ", seq)
which is not what we want.

Retrospecively applying this thought,
a string cannot have a join method.
Or the str class needs to have a class method
of
   str.join(seq, " ")
as well.

Have to ask Tim about that.

if-you-want-it-perfect-first-time-you-won't-get-anything - chris
-- 
Christian Tismer             :^)   <mailto:tismer at 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/







More information about the Python-list mailing list