How do I catch the output from PyErr_Print() (or anything that prints to stdout/stderr)?

In Python code, define an object with a write method that takes a single string argument. Assign this object to