email module, redirecting to stdout

Just just at xs4all.nl
Tue Oct 4 10:25:04 EDT 2005


In article <dhu2vh$ivo$00$1 at news.t-online.com>,
 Peter Otten <__peter__ at web.de> wrote:

> Laszlo Zsolt Nagy wrote:
> 
> > I have this code:
> > 
> >         s = smtplib.SMTP()
> >         s.set_debuglevel(1)
> >         s.connect(host=smtp_host)
> >         s.set_debuglevel(0)
> >         log("Connected, sending e-mail")
> >         sys.stdout.flush()
> >         s.sendmail(
> >             consts.EMAIL_FROMADDRESS,
> >             [to],
> >             msg.as_string()
> >         )
> >         log("E-mail sent OK")
> >         s.quit()
> > 
> > The problem is that whenever I set the debuglevel to 1, messages will go
> > to stderr. I would like them to go to stdout. Using
> > 
> > sys.stderr = sys.stdout
> > 
> > has no effect. Redirecting stderr to stdout from the shell is not an
> > option for me, because I need to use stderr for other messages.
> 
> smtplib obtains a copy of stderr by
> 
> from sys import stderr
> 
> Therefore you have to do
> 
> smtplib.stderr = sys.stdout
> 
> to get the desired effect.

Ouch. I'd consider this a bug. "from sys import stderr" should at least 
be considered bad style.

Just



More information about the Python-list mailing list