Python stdout from PyCall

Hi all
I’m using PyCall to run a whole script.

julia> @pyinclude("")

The script prints out a stream of data to Python stdout

 print( date_test ,"^ ", telle, norman,)

How do I access python stdout from the Julia script. So I’d like to process the same stream in Julia. I’m still learning how to use PyCall.

Just set sys.stdout to a Julia stream. You can even set it to be a Julia buffer:

julia> using PyCall

julia> buf = IOBuffer();

julia> pyimport("sys").stdout = buf;

julia> py"print('hello world')"

julia> String(take!(buf))
"hello world\n"

thank you, I like the idea of setting it as a buffer. PyCall is a remarkably useful transition tool from Python to Julia. Thank you so much for putting it all together. Have an excellent weekend.