[Python] How to write exceptions traceback to a file using python

Discussão em 'Python' iniciado por Stack, Junho 21, 2025.

  1. Stack

    Stack Membro Participativo

    Currently, my code gives traceback exception in console as per my expectations. I want to write exceptions to a file but code is not writing any exceptions to the file. A file is created but it is blank.

    except Exception as error:
    print(traceback.print_exc())
    f = open('ErrorFile.txt', 'w')
    f.write(traceback.print_exc())
    f.close()

    Continue reading...

Compartilhe esta Página