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

Michael Goral bcd240 at gmail.com
Mon May 1 15:52:47 CEST 2006


> Thomas Wouters wrote:
> "I disagree, and I believe that would be a big mistake to change it."

seems to me that Thomas is right here ...

some remarks by a recent arrival at Python, my initial offset was
version 2.4.0: I think cleaning up things to ease newbie adaptation is
often misleading

I view the tree empty pairs of parenthesis, brackets and braces to
signify the three fundamental container types almost as a *trademark*
of Python: "look here, this is Python ...", and these pairs highlight
the most important focus of all things Python: "simple, yet powerful"
(okay, later on you will apply the related type functions more often,
every newbie will follow this path and turn to a non-newbie soon ...)

even the quirky need to sometimes replace () with (,) is *minor
trademark-ig*, as the meaning of () is kind of shallow compared to the
deep significance of [] and {}.

realising that 'a' + 'bb' + 'ccc' is bad yields the mental rule "do
apply the concatenation operator to pairs of strings only", which
brings us to the str-method 'join' and makes this method pretty
important:

tc = ('a', 'bb', 'ccc')
' <> '.join(tc)

ss = ' <> '
tcInner = tc
tcOuter = (ss[-2:], ss[:2])

ss.join(tcInner).join(tcOuter)
--> '> a <> bb <> ccc <'

a.join(b) is another idiom of *minor trademark-ig* quality

''.join(x) highlights (for a newbie) that any string in Python is an
object hosting methods, the beauty here is symmetry:
' <> '.join(tc)
--> 'a <> bb <> ccc'

and not 'a <> bb <> ccc <> ' or ' <> a <> bb <> ccc' - something to be
cleaned up afterwards most often

[ is /a/ in 'a.join(b)' a delimiter? generally speaking: no! ]

if this 'join' is a successful idiom (I do think so), then it is/would
be healthy, if there was no other idiom using 'join' - another point:
such a solitary 'join' easily builts up a rich specific meaning "und
das ist Rückenwind"

last remark:
coming across the 'enumerate' function (as a newbie), this phrase was
not speaking to me, I could not guess what it's purpose might be ...
afterwards it turned into a powerful idiom that is (for me) not
disturned by the plain meaning of 'enumerate':

x, y in enumerate(z)

--Michael


More information about the Python-3000 mailing list