iqrf 3 Posted May 18, 2023 Hello, is there any way to remap PyErr_Print using a custom function? I would like to log the error output on a separate sheet. Now everything ends up in TPythonInputOutput. Or can it be done differently? Thanks for the idea. Share this post Link to post
KoRiF 1 Posted May 19, 2023 I think the best you can is to refer to the PythonEngine's DoRedirectIO sources the line sys.stdin=sys.stderr=sys.stdout=DebugOutput() redirects error output onto PythonEngine.IO so far you could try to use other redirection somewhere in your code Hope this helps Share this post Link to post
pyscripter 689 Posted May 19, 2023 from io import StringIO import sys old_stderr = sys.stderr sys.stderr = mystderr = StringIO() # examine mystderr.getvalue() Share this post Link to post
iqrf 3 Posted May 23, 2023 Thanks, it works. try MaskFPUExceptions(True); PythonEngine1.ExecStrings(Memo1.Lines); except errorMessage := MainModule.mystderr.getvalue(); ErrorLog(errorMessage); end; I would just like to continuously catch errors if someone writes in the Python code for example print("Error example 1", file=sys.stderr) or sys.stderr.write("Error Example 2") The current solution only prints everything at once, with the same timestamp. Thanks. Share this post Link to post