Jump to content

TPythonInputOutput separation Python Error

Recommended Posts

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

I think the best you can is to refer to the PythonEngine's DoRedirectIO sources


the line


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
from io import StringIO
import sys

old_stderr = sys.stderr
sys.stderr = mystderr = StringIO()

# examine mystderr.getvalue()


Share this post

Link to post

Thanks, it works.


    errorMessage := MainModule.mystderr.getvalue();

I would just like to continuously catch errors if someone writes in the Python code for example print("Error example 1", file=sys.stderr)
sys.stderr.write("Error Example 2")
The current solution only prints everything at once, with the same timestamp.


Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now