Programming Python 2E: question on smtplib example

Tim Roberts timr at probo.com
Thu May 30 00:30:52 EDT 2002


Daniel Klein <danielk at aracnet.com> wrote:

>On page 612 of PP2E, the example has the following line of code...
>
>To = string.split(To, ';')   # allow a list of recipients
>
>,,,and then a few lines down...
>
>text = ('From: %s\nTo: %s\nDate: %s\nSubject: %s\n'
>        % (From, string.join(To, ';'), date, Subj))
>
>The question is: Why even do the split() and join() since all this seems to
>do is take the 'To' variable on a round trip?

My guess is that "To" is later passed as a parameter to smtplib.sendmail.
In that case, it needs to be a list of strings, not a single string.

I have found that the best way to exploit Python is to think of my data in
terms of lists and tuples.  Split and join are quick primitives.  In this
example, their use will let you add features later that would be difficult
with a single string.
--
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list