smtplib, capturing output from set_debuglevel ??

Tim Williams listserver at tdw.net
Thu Oct 7 14:33:33 EDT 2004


----- Original Message ----- 
From: "Steve Holden" <steve at holdenweb.com>


> Tim Williams wrote:
>
> > Can anyone suggest a way of capturing the output from smtplib's
> > set_debuglevel

> All smtplib debug output is produced using print statements to standard
> ouput, so you could try creating a "file-like" object (such as a
> cStringIO) and temporarily replacing sys.stdout with it (saving
> sys.sdout and replacing it if other parts of your program need to use it).
>
> If you need help to work out the details, post again.

Many thanks Steve

I have implemented your suggestion ,   but what is the best way to get the
data out of the file-like object,   the only option that seems to work for
me is

f.getvalue()

which returns a string,  but getvalue() doesn't "feel" right somehow.   Am I
missing something ?

TIA















More information about the Python-list mailing list