I come to praise .join, not to bury it...

Mark Pilgrim f8dy at yahoo.com
Fri Mar 9 19:26:48 CET 2001

"Alex Martelli" <aleaxit at yahoo.com> wrote in message
news:98aspo024jg at news2.newsguy.com...
> But the .join/.writelines parallel is VERY close, so why
> would the SAME architectural choice (to have the sequence
> object as an argument, accessing it through its ability
> to enumerate its items, only) cause problems in one case
> and not the other?!
> I think it's a misperception due to thinking of strings
> as somehow 'passive', 'data', while a file-object is
> thought of as 'active', 'a truly object-y object', or
> something.

Exactly!  I have taught Python to half a dozen people in the last few
months, and every one of them had trouble with this concept, because they
all came from a C background where they only thought of "string" as "packed
array of char", or some other language (like Powerbuilder) where "string" is
just a native datatype and isn't an object in any sense of the word.  Nobody
minded file objects, even if they were only used to using integer file
handles in their previous language.  I think that's because they could build
a mental model of a file object as a kind of secretary who has a copy of a
document on their desk and can read you various parts of it, or all of it,
or tell you its title, or whatever.  But everybody had trouble with string
objects, because the mental model is different.

IIRC, the post that started the thread that spawned this thread quoted a
code sample from my book, something like this:
    return ";".join([...])
There are obviously lots of ways to do this (assign ";" to a variable first,
or use the old string.join function, or don't use join at all), but I did it
this way on purpose.  Call it shock value, for lack of a better term -- to
force the point that the literal string ";" is an object, not just string
variables.  I have gotten multiple e-mails from readers telling me that this
was their "a-ha!" moment when they realized that everything in Python really
*is* an object.  After that moment, they don't mind seeing modules that have
attributes, or functions passed around as parameters, or anything other
weird/cool/wicked-ness.  "Sure, you can do that, you can do anything,
because everything is an object; just look at what you can do with string

You're smart; why haven't you learned Python yet?

More information about the Python-list mailing list