By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,922 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,922 IT Pros & Developers. It's quick & easy.

putting the output of a print statement into a string

P: n/a
There are objects whose repr() is not the same
as what gets printed out when you apply the
print statement to them. Usually these are
complex objects like exceptions.

Example:
import smtplib server=smtplib.SMTP("smtp.yourisp.com") try: server.sendmail("xx*@in88validdomain.com",
"xx*@abc.com","message")

except smtplib.SMTPRecipientsRefused, senderrs:
exc_obj=senderrs
repr(exc_obj) '<smtplib.SMTPRecipientsRefused instance at 0x00EA7C60>'
print exc_obj

{'xx*@abc.com': (550, 'Verification failed for <xx*@in88validdomain.com>\nunrouteable mail domain "in88validdomain.com"\nSender
verify failed')}
Question:

Is there a way to somehow put the output of 'print exc_obj' into
a string?


Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
In <3a*************@individual.net>, Jon Perez wrote:
Question:

Is there a way to somehow put the output of 'print exc_obj' into
a string?


There are ways to do even that, but maybe ``str(exc_obj)`` is enough for
your needs!?

Ciao,
Marc 'BlackJack' Rintsch
Jul 18 '05 #2

P: n/a
Thanks, man! That was one fast reply...

Marc 'BlackJack' Rintsch wrote:
In <3a*************@individual.net>, Jon Perez wrote:

Question:

Is there a way to somehow put the output of 'print exc_obj' into
a string?

There are ways to do even that, but maybe ``str(exc_obj)`` is enough for
your needs!?

Ciao,
Marc 'BlackJack' Rintsch

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.