0

I have written a script in Python. It has a GUI which I intend to distribute to my colleagues. If when they run it and encounter a bug, is there a way to have these errors be written to a text file so I can know what the bug was? In Jupyter notebook whenever I encounter a bug in my script, it shows as Traceback error. I want to see that kind of information in the text file whenever someone finds a bug.

Thank you

rmore911
  • 195
  • 2
  • 13

1 Answers1

0

You could try something like this

import time
import os
import sys

def logger(logfile, bolus):
# Takes two inputs - logfile (path to desired file), and data to be written
# Writes "Y-M-D|H:M:S, bolus\n"
    f = open(logfile, 'a+')
    currentdate = time.strftime('%Y-%m-%d|%H:%M:%S')
    f.write(currentdate + ',' + data +'\n')
    f.close()
stygarfield
  • 107
  • 9