Embedded python: printing exceptions to a file?

Scott David Daniels Scott.Daniels at Acm.Org
Sun Jan 5 12:38:34 EST 2003


 > I want to log errors from python scripts  running in
 > the embedded interpreter to a log file.

I am guessing a bit here about your need.  If you want your
errors logged onto a file, in the python language, before you
start your python code, execute the string:
     "import sys\nsys.stderr = open('log.file', 'a')\n"
and finish (possibly via a try-finally) with:
     "sys.stderr,close()"

If you want the text available to your application, you'll
probably want to use StringIO/cStringIO something like:
     "import cStringIO,sys\nsys.stderr=cStringIO.StringIO()\n"
and then, once your code is finished, get your error output with:
     "sys.stderr.getvalue()"

As to the <OT>,
 >...splitup this newsgroup into some more specific subjects like...
Unfortunately, much of the original query posting to such piles
of newsgroups get sent to all of the groups "just in case."  Thus
you wind up with more total traffic and less information.  At least
heare you have a great Google search source.

-Scott David Daniels
Scott.Daniels at Acm.Org





More information about the Python-list mailing list