[Tutor] string.join()

Monte Milanuk monte at milanuk.net
Mon Nov 3 15:54:33 CET 2008


Hello again,

Just looking for clarification on a point:  the book I'm using is written around Python v.2.3, and has an exercise using string.join().  Specifically, it said to use string.join(msgList, ""), the object of which was to take the list items in msgList and concatenate them using a blank or no character between.  After some work it did work as advertised, which is all well and good, but I hit a bit of a snag along the way.  I *think* I got it figgered out, but would like some verification.  

Basically... when I was reading through the documentation trying to decide how to re-write an earlier program using string.join() as described above... I noticed the docs said that a bunch of  string functions were deprecated and going away in Python 3.0.  As such... I thought perhaps since I was in the neighborhood so to speak maybe I should learn to do things the 'new' way.  It took me a while to get from string.join(words[, sep]) to str.join()... which almost immediately puked and didn't work.  After a while longer, I finally noticed somewhere that 'str' was supposed to be the string used for the separator, so I use ''.join(msgList), which seems to work (or at least give identical output) in this case.

So... do I have it correct?  Yes/no/maybe?

Thanks,

Monte
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081103/1ffe17f8/attachment.htm>


More information about the Tutor mailing list