# Python stdout from PyCall

**URL:** <https://discourse.julialang.org/t/python-stdout-from-pycall/75036>\
**Category:** New to Julia\
**Tags:** package, pycall\
**Created:** [January 22, 2022, 3:23pm UTC](https://discourse.julialang.org/t/python-stdout-from-pycall/75036 "2022-01-22T15:23:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)\
**Post date:** [January 22, 2022, 3:23pm UTC](https://discourse.julialang.org/t/python-stdout-from-pycall/75036/1 "2022-01-22T15:23:42Z")

</div>

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

```julia
julia> @pyinclude("test_print.py")

```

The script prints out a stream of data to Python stdout

```julia
 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.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 22, 2022, 5:23pm UTC](https://discourse.julialang.org/t/python-stdout-from-pycall/75036/2 "2022-01-22T17:23:08Z")

</div>

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

```julia
julia> using PyCall

julia> buf = IOBuffer();

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

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

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

```

---

<div class="post-metadata">

**Author:** ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)\
**Post date:** [January 22, 2022, 5:50pm UTC](https://discourse.julialang.org/t/python-stdout-from-pycall/75036/3 "2022-01-22T17:50:39Z")

</div>

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.
