# Output-like print

**URL:** https://discourse.julialang.org/t/output-like-print/6930
**Category:** General Usage
**Tags:** question
**Created:** [November 7, 2017, 11:00am UTC](https://discourse.julialang.org/t/output-like-print/6930 "2017-11-07T11:00:10Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [November 7, 2017, 11:00am UTC](https://discourse.julialang.org/t/output-like-print/6930/1 "2017-11-07T11:00:10Z")

</div>

Compare this:

![image](https://global.discourse-cdn.com/julialang/original/3X/6/1/6199aaca0d00e57e1501becb0fd32186d6c1c981.png)

to this:

![image](https://global.discourse-cdn.com/julialang/original/3X/4/5/4579cca6ea08325c0c1cefc6b5fb6b81bdb3946c.png)

or this:

![image](https://global.discourse-cdn.com/julialang/original/3X/1/9/19891654f55a7cf666dc68e1d81c5de33da3707f.png)

How can I “print” a value, to be formatted like it would if it was output (like in the first case)?

The problem with just outputing (like in the first case) is that you can only do it once per cell, since only the last expression is returned. I would like to print multiple values (with output format) from the same cell.

---

<div class="post-metadata">

### Author: ![swt30](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/swt30/32/4667_2.png) [@swt30](https://discourse.julialang.org/u/swt30)
#### Post date: [November 7, 2017, 11:22am UTC](https://discourse.julialang.org/t/output-like-print/6930/2 "2017-11-07T11:22:07Z")

</div>

I think you want `display`:

```nohighlight
julia> display(Dict(i => i^2 for i = 1:5));
Dict{Int64,Int64} with 5 entries:
  4 => 16
  2 => 4
  3 => 9
  5 => 25
  1 => 1

```

---

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [November 7, 2017, 11:41am UTC](https://discourse.julialang.org/t/output-like-print/6930/3 "2017-11-07T11:41:38Z")

</div>

For some reason it doesn’t respect the order in which I print things.

![image](https://global.discourse-cdn.com/julialang/original/3X/d/f/dff10ecce81bda484f961ac02b89b7136f4c980d.png)

Any idea how I can resolve that?

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [November 7, 2017, 11:57am UTC](https://discourse.julialang.org/t/output-like-print/6930/4 "2017-11-07T11:57:14Z")

</div>

Try

```julia
julia> show(STDOUT, MIME("text/plain"), Dict(1=>2, 2=>3))
Dict{Int64,Int64} with 2 entries:
  2 => 3
  1 => 2

```

---

<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: [November 7, 2017, 12:53pm UTC](https://discourse.julialang.org/t/output-like-print/6930/5 "2017-11-07T12:53:29Z")

</div>

What you’re seeing is the difference between the two-argument `show(io, x)` (called by `print`) and the three-argument `show(io, "text/plain", x)` (called by `display`). See [https://docs.julialang.org/en/stable/manual/types/#Custom-pretty-printing-1](https://docs.julialang.org/en/stable/manual/types/#Custom-pretty-printing-1)

---

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [November 7, 2017, 12:55pm UTC](https://discourse.julialang.org/t/output-like-print/6930/6 "2017-11-07T12:55:12Z")

</div>

Why the order between `print` and `display` calls is not respected?

---

<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: [November 7, 2017, 4:52pm UTC](https://discourse.julialang.org/t/output-like-print/6930/7 "2017-11-07T16:52:46Z")

</div>

> [@e3c6](#):
>
> Why the order between print and display calls is not respected?

In IJulia/Jupyter, `print` output (i.e. stdio output) and `display` output use different mechanisms.

`STDOUT` is flushed to the notebook display via [“stream” output messages](http://jupyter-client.readthedocs.io/en/latest/messaging.html#streams-stdout-stderr-etc). This only happens at certain intervals — every `print` statement does not trigger an individual stream message.

Each `display` call, on the other hand, sends an individual [“display\_data” message](http://jupyter-client.readthedocs.io/en/latest/messaging.html#display-data). This is because `display(x)` output is **not limited to text** : for a given `x`, it outputs in the richest format supported by `x` and by Jupyter. e.g. it could output an image or a LaTeX-formatted equation.

As a result, `display` and `print` outputs do not necessarily appear in order.

In general, you cannot assume that `display` output goes to `STDOUT`, unlike `print`. e.g. `display(x)` may open up a separate window with an image, etcetera. `display(x)` means “show `x` in the best way you can for the current output device(s)”. If you want REPL-like text output that is guaranteed to go to `STDOUT`, use `show(STDOUT, "text/plain", x)` instead.

---

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [November 7, 2017, 4:58pm UTC](https://discourse.julialang.org/t/output-like-print/6930/8 "2017-11-07T16:58:17Z")

</div>

Thanks for the answer.
