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

1

1 Answer 1

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()
Sign up to request clarification or add additional context in comments.

2 Comments

Python supports filehandler for logging exceptions in a file. Why can't we use that instead?
Probably a better solution - I'm pretty new myself and this is what I use for debugging 🤷‍♂️

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.