Python stdout from 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"
3 Likes