why sys.stdout returned null

Environment

  • Pythonnet version: 2.2.2 (.NET 4, x64)
  • Python version: 3.5
  • Operating System: Windows 10

Details

Python is embedded in my .NET application using pythonnet. I found the output of the print statement in a python script is not showing on the screen until a "sys.stdout.flush()" called. I don't known how to redirect sys.stdout in .NET.
In order to call the flush() method directly in .NET, I tried

dynamic sys = PythonEngine.ImportModule("sys");
var stdout= sys.GetAttr("stdout"); // returns None

and both sys.stdout and the variable stdout returned are None here.

In python, I tried

import sys
print(getattr(sys, 'stdout'))

and it outputs a _io.TextIOWrapper object.

Why sys.stdout returned null here? How to make the output of python print statement show automatically?

Thanks.