Extracting the traceback

billiejoex gnewsg at gmail.com
Tue Aug 21 19:53:31 EDT 2007


Hi there,
I'm facing a case where I need to get the traceback outptut when
occurring an exception.
I solved such problem by using traceback module in conjunction with
StringIO:

import StringIO, traceback
try:
    raise Exception
except:
    f = StringIO.StringIO()
    traceback.print_exc(file=f)
    print f.getvalue()

... but this seems a little poor to me since I first put output into
the StringIO.StringIO(), then I get it back by using getvalue() on
it.
Is there a way to avoid the use of StringIO and get such output
without using such (useless) additional step?

Thanks in advance




More information about the Python-list mailing list