Writing traceback of an exception into a log-file

Dominique.Holzwarth at ch.delarue.com Dominique.Holzwarth at ch.delarue.com
Mon May 26 04:31:27 EDT 2008


Hi all

I'm trying to write the traceback stack of an exception that is thrown into a log file, but currently all that's written is simply a "None" :-/

Here's some example code of what I'm doing:

Import traceback
class myException(Exception):
        def __init__(self):
                f = open('filename.txt', 'a')
                traceback.print_exc(file=f)
                f.close()

The file handling (opening etc) works ok (I'm using the same file in combination with a Logger() object too) but the string written to the file is effectively just a "None".

Could anyone explain to me how to properly use the traceback module with it's countless of functions? =)

Thanks in advance,
Dominique


*****************************************************************************
This e-mail and any files attached are strictly confidential, may be legally
privileged and are intended solely for the addressee. If you are not the
intended recipient please notify the sender immediately by return email and
then delete the e-mail and any attachments immediately.

The views and or opinions expressed in this e-mail are not necessarily the
views of De La Rue plc or any of its subsidiaries and the De La Rue Group
of companies, their directors, officers and employees make no representation
about and accept no liability for its accuracy or completeness.

You should ensure that you have adequate virus protection as the De La Rue
Group of companies do not accept liability for any viruses.

De La Rue plc Registered No.3834125, De La Rue Holdings plc Registered
No 58025 and De La Rue International Limited Registered No 720284 are all
registered in England with their registered office at:
De La Rue House, Jays Close, Viables, Hampshire RG22 4BS
*****************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080526/7cfc488a/attachment.html>


More information about the Python-list mailing list