Dup Goto 📝

TracebackModule

PT2/aw/lang/python 07-31 13:46:41
To Pop
12 lines, 36 words, 411 chars Monday 2023-07-31 13:46:41

See docs here. Note that sys.exception(), within an except, returns the current exception.

import traceback
from datetime import datetime
try:
  open("does_not_exist")
except Exception as e:
  traceback.print_exc()
  with open("exc.txt","at") as f:
    print(f"==[ {datetime.now().strftime('%c')} ]==",file=f)
    traceback.print_exc(file=f)