############### ############### ############### ############### #########
import traceback
class MyTraceback:
def __init__(self):
self.clear()
def clear(self):
self.s = ''
def write(self, s):
self.s += s
def read(self):
return self.s
def catch(self):
traceback.print _exc(None, self)
if __name__ == '__main__':
myTcb = MyTraceback()
try:
a = 1/0
except:
myTcb.clear()
myTcb.catch()
print myTcb.read()
############### ############### ############### ############### ##########
Call clear() each time before you expect a new traceback output. You can
import this class and don't need to import traceback in your main project.
Oliver
"John Hunter" <jd******@ace.b sd.uchicago.edu > wrote in message
news:ma******** *************** **************@ python.org...
What is the best way to get the traceback as a string.
I define the following module "Excepts.py " for logging exceptions in daemon
processes:
------------------------------------------
import sys,traceback
def error():
tb =
traceback.forma t_exception(sys .exc_info()[0],sys.exc_info()[1],sys.exc_info(
)[2])
return tb[len(tb)-1].replace('\n',' ')
def errorstack():
return
''.join(traceba ck.format_excep tion(sys.exc_in fo()[0],sys.exc_info()[1],sys.e
xc_info()[2]))
-------------------------------------------
Colin Brown
PyNZ
--
http://mail.python.org/mailman/listinfo/python-list