[python-win32] WMI troubles!

Tim Golden mail at timgolden.me.uk
Fri Jan 15 21:19:37 CET 2010


On 15/01/2010 18:26, Alex Hall wrote:
> What is the syntax to write the traceback to a text file? I have the
> file object and I can open and close the file, I just need the command,
> like "f.write(StackTrace())" or whatever the command is. I will try the
> alt-space idea as well.

Just to answer this question on its own for the moment:
the following code is the kind of thing you can use
to trap an error and write the traceback to a file.
(You could also use the stdlib logging module):

<code>
import traceback

try:
   1 / 0 # or something more useful
except:
   with open ("error.log", "a") as f:
     traceback.print_exc (file=f)
     # or f.write (traceback.format_exc ())

</code>

TJG


More information about the python-win32 mailing list