# Print statements in pyjulia

**URL:** <https://discourse.julialang.org/t/print-statements-in-pyjulia/18901>\
**Category:** General Usage\
**Created:** [December 21, 2018, 3:49pm UTC](https://discourse.julialang.org/t/print-statements-in-pyjulia/18901 "2018-12-21T15:49:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaelkyu](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@michaelkyu](https://discourse.julialang.org/u/michaelkyu)\
**Post date:** [December 21, 2018, 3:49pm UTC](https://discourse.julialang.org/t/print-statements-in-pyjulia/18901/1 "2018-12-21T15:49:41Z")

</div>

In [pyjulia](https://github.com/JuliaPy/pyjulia), how do I get “print” statements to show up in the Python terminal? For example, this doesn’t print anything

> \>\>\> Main.eval(“print(123)”)

My real use case is to get the results from @benchmark

> \>\>\> Main.eval(“”"  
> using BenchmarkTools  
> @benchmark x = 123"“”)

---

<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:** [December 21, 2018, 4:56pm UTC](https://discourse.julialang.org/t/print-statements-in-pyjulia/18901/2 "2018-12-21T16:56:36Z")

</div>

See the discussion in [Redirect julia STDOUT to python sys.stdout? · Issue #49 · JuliaPy/pyjulia · GitHub](https://github.com/JuliaPy/pyjulia/issues/49)

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [December 21, 2018, 10:26pm UTC](https://discourse.julialang.org/t/print-statements-in-pyjulia/18901/3 "2018-12-21T22:26:06Z")

</div>

Are you using it in standard `python` REPL? I think `print` etc. in Julia should work without any tricks. (Using PyJulia in Jupyter Notebook/Lab needs more improvements, though.)

What is your output when you evaluated the following?

```python
>>> from julia import Main
>>> Main.eval("stdout")
<julia.core.PyIO object at 0x7f46f0075518>
>>> import sys
>>> sys.stdout
<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>

```

(In case you are using Julia 0.6, it’s `Main.eval("STDOUT")`.)

---

<div class="post-metadata">

**Author:** ![michaelkyu](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@michaelkyu](https://discourse.julialang.org/u/michaelkyu)\
**Post date:** [December 21, 2018, 10:55pm UTC](https://discourse.julialang.org/t/print-statements-in-pyjulia/18901/4 "2018-12-21T22:55:39Z")

</div>

I was originally testing code on a Jupyter notebook. When I run `Main.eval(“print(123)”)` in the standard python REPL, the output does show up! However, even in the REPL, I still don’t see the results of `Main.eval("""@benchmark x = 123""")`

On the code you asked me to evaluate:

```julia
#####################################
# Evaluated on standard Python REPL #
#####################################
>>> from julia import Main
>>> Main.eval("stdout")
<julia.core.PyIO object at 0x7f46f0075518>
>>> import sys
>>> sys.stdout
<_io.TextIOWrapper name='<;stdout>' mode='w' encoding='UTF-8'>;

```

```julia
#################################
# Evaluated on Jupyter notebook #
#################################
from julia import Main
Main.eval("stdout")
<julia.core.PyIO at 0x7f0bf46a12b0>

import sys
sys.stdout
<ipykernel.iostream.OutStream at 0x7f0bf800dcc0>

```

I’m using Python 3.7.0, IPython 7.2.0, Julia 1.0.2, and the latest github master version of pyjulia (0.2.1.dev0)

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [December 21, 2018, 11:14pm UTC](https://discourse.julialang.org/t/print-statements-in-pyjulia/18901/5 "2018-12-21T23:14:01Z")

</div>

I guess you saw `<PyCall.jlwrap Trial(0.024 ns)>` as below? This is because Julia REPL runs `display` on the returned value of the expression you type. In `python` REPL, you need to run it manually, like this:

```python
>>> from julia import Main
>>> Main.eval("using BenchmarkTools")
>>> Main.eval("@benchmark 1")
<PyCall.jlwrap Trial(0.024 ns)>
>>> Main.display(_)
BenchmarkTools.Trial:
  memory estimate: 0 bytes
  allocs estimate: 0
  --------------
  minimum time: 0.024 ns (0.00% GC)
  median time: 0.029 ns (0.00% GC)
  mean time: 0.030 ns (0.00% GC)
  maximum time: 13.283 ns (0.00% GC)
  --------------
  samples: 10000
  evals/sample: 1000>>>
>>>
>>> Main.eval("display(@benchmark 1); println()")
BenchmarkTools.Trial:
  memory estimate: 0 bytes
  allocs estimate: 0
  --------------
  minimum time: 0.026 ns (0.00% GC)
  median time: 0.030 ns (0.00% GC)
  mean time: 0.031 ns (0.00% GC)
  maximum time: 0.197 ns (0.00% GC)
  --------------
  samples: 10000
  evals/sample: 1000
>>>

```

I know this needs improvement. Python does not have a systematic display system like Julia so it’s a bit hard. But we can do it in IPython as it has an excellent display system. Mapping Julia’s display system to IPython’s will be done in [https://github.com/JuliaPy/PyCall.jl/issues/617](https://github.com/JuliaPy/PyCall.jl/issues/617). For I/O support in Jupyter, see [Redirect julia STDOUT to python sys.stdout? · Issue #49 · JuliaPy/pyjulia · GitHub](https://github.com/JuliaPy/pyjulia/issues/49) as @stevengj suggested.

---

<div class="post-metadata">

**Author:** ![michaelkyu](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@michaelkyu](https://discourse.julialang.org/u/michaelkyu)\
**Post date:** [December 21, 2018, 11:21pm UTC](https://discourse.julialang.org/t/print-statements-in-pyjulia/18901/6 "2018-12-21T23:21:24Z")

</div>

Ok, thank you for the explanation!
