Re: how to save errors in a file in python
Re: how to save errors in a file in python @3That's probably not a great idea, since it'll break output redirection or whatever it's called when you do:python script.py > errors.log 2>&1A better solution would probably be to override sys.excepthook, and write your errors to a file, before letting the default sys.excepthook do it's thing:import sys from traceback import format_exception _excepthook = sys.excepthook filename = 'errors.log' def excepthook(type, value, traceback): print(f'Writing exception to {filename}...') try: with open(filename, 'a') as f: f.writelines(format_exception(type, value, traceback)) print('Error saved.') except Exception as e: print('Failed to save error:') print('\n'.join(format_exception(type(e), e, e.__traceback__))) return _excepthook(type, value, traceback) sys.excepthook = excepthookI've tested this, and it works fine. Still possibly not recommended, since there's probably error cases I've not thought of. URL: https://forum.audiogames.net/post/580376/#p580376 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: how to save errors in a file in python
Re: how to save errors in a file in python Here's what I use.import os import sys def main(): if os.path.isdir("data") == False: os.mkdir("data") f2 = open("errors.log", "a") sys.stderr = f2 URL: https://forum.audiogames.net/post/580336/#p580336 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: how to save errors in a file in python
Re: how to save errors in a file in python Here's what I use.import os import sys def main(): if os.path.isdir("data") == False: os.mkdir("data") f2 = open("errors.log", "a") sys.stderr = f2 URL: https://forum.audiogames.net/post/580336/#p580336 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: how to save errors in a file in python
Re: how to save errors in a file in python The hacky answer is wrap your program in:try: stuff except e: do stuff to errors hereThen use the normal Python file writing stuff and the traceback module to format it however you want. The docs on the traceback module explain how.But the real answer is use the logging module, pick a logging library that you like, and go to town with it. URL: https://forum.audiogames.net/post/579665/#p579665 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
how to save errors in a file in python
how to save errors in a file in python hey friends, so, if you have played shooter cd by mason then you notice all the errors saved in a log file. but there, you get a error dialog. but errors are saved in log file. how to do that in python? shooter is also written in python so, i know this python script.py 2>error.log but how to do that in executable compiled by pyinstaller?thanks in advance URL: https://forum.audiogames.net/post/579661/#p579661 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector