473,382 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

putting the output of a print statement into a string

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
2 1410
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Joe Flynt | last post by:
I'm try to display the output of ipconfig.exe to the web browser using: Apache/2.0.48 (Win32) mod_python/3.1.2b Python/2.3.2 but when I view http://server/cgi-bin/test.py i get the following...
14
by: Marcin Ciura | last post by:
Here is a pre-PEP about print that I wrote recently. Please let me know what is the community's opinion on it. Cheers, Marcin PEP: XXX Title: Print Without Intervening Space Version:...
2
by: Jason | last post by:
Hello, I have a class, transCore, that does certain work, and by default, prints its progress to the stand output. Later, I will to write a GUI class that encapsulate the transCore class. I...
1
by: Little | last post by:
Could someone start me on putting in a table into this code, and some HTML tags. I would to make the table below the map and have a header at the top. Thanks for the help. """ Publisher example...
10
by: Johannes Barop | last post by:
Hi, I want to format the output of a 'std::ostream', but i dont know how to do it . Example: int main() { my_out << "Hi.\nI'am a" << " Computer."; my_out << "Nice.";
5
by: heidi.hunter | last post by:
I just downloaded the most recent (2.4.3) Python and IDLE (1.1.3) to Windows XP Professional. I'm new to the IDLE environment, so hopefully someone can tell me what I'm missing here! Below is the...
14
by: fdu.xiaojf | last post by:
Hi, I'm writing a program which imports an external module writing in C and calls a function provided by the module to do my job. But the method produces a lot of output to the stdout, and this...
0
by: Pradnyesh Sawant | last post by:
Hello, I need the cpu usage of a linux box, for which i capture the output of "top" using "popen". However, i am facing problems during string handling. The code snippet is:- top =...
0
by: jebbyleezer | last post by:
Hello, I have source code that builds correctly, however, after the program terminates the output file produced is empty. Here is my source code: import java.io.*; import java.util.Scanner;...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.