# Human-readable but precise printing of data

**URL:** https://discourse.julialang.org/t/human-readable-but-precise-printing-of-data/2212
**Category:** General Usage
**Tags:** question
**Created:** [February 21, 2017, 11:52am UTC](https://discourse.julialang.org/t/human-readable-but-precise-printing-of-data/2212 "2017-02-21T11:52:47Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [February 21, 2017, 11:52am UTC](https://discourse.julialang.org/t/human-readable-but-precise-printing-of-data/2212/1 "2017-02-21T11:52:47Z")

</div>

How should I print data in Julia so that

1. the output contains all the information (full precision for floats, type information for literals, etc),
2. the output is plain text.

Eg with `show`, type information and precision is lost:

```julia
julia> d = Dict(:a => √2, :b => fill(1/3, 3), :c => 1f0)
Dict{Symbol,Any} with 3 entries:
  :c => 1.0
  :a => 1.41421
  :b => [0.333333,0.333333,0.333333]

```

while `serialize` does preserve everything, but is not plain text. I would be satisfied with something that handles everything but functions/closures.

---

<div class="post-metadata">

### Author: ![TsurHerman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tsurherman/32/1234_2.png) [@TsurHerman](https://discourse.julialang.org/u/TsurHerman)
#### Post date: [February 21, 2017, 1:07pm UTC](https://discourse.julialang.org/t/human-readable-but-precise-printing-of-data/2212/2 "2017-02-21T13:07:30Z")

</div>

Accidently I think I have an answer for you… just messed up with it a little bit myself.  
So digging through the julia base I think this is what you are looking for:

```julia
sprintf_exact(x) = sprint(0,print,x; env = (:compact => false))

```

for your simple example it works.  
lets validate it:

```julia
julia> d = Dict(:a => √2, :b => fill(1/3, 3), :c => 1f0);

julia> f = eval(parse(sprintf_exact(d)));

julia> f === d
false

julia> f == d
true

```

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [February 21, 2017, 1:16pm UTC](https://discourse.julialang.org/t/human-readable-but-precise-printing-of-data/2212/3 "2017-02-21T13:16:35Z")

</div>

> [@TsurHerman](#):
>
> sprintf\_exact(x) = sprint(0,print,x; env = (:compact =\> false))

Thanks. I think that adding this as `print_parseable` or something similar would be worthwhile, but I need to understand Julia’s printing system in depth before opening an issue.

---

<div class="post-metadata">

### Author: ![TsurHerman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tsurherman/32/1234_2.png) [@TsurHerman](https://discourse.julialang.org/u/TsurHerman)
#### Post date: [February 21, 2017, 1:20pm UTC](https://discourse.julialang.org/t/human-readable-but-precise-printing-of-data/2212/4 "2017-02-21T13:20:57Z")

</div>

print is already parsable … I think it is by design.  
to get full precision in print use:

`print(IOContext(STDOUT;compact = false) , 1/3)`

if you are not worried about precision then sprintf\_exact boils down to  
`sprint(print,x)`

---

<div class="post-metadata">

### Author: ![fengyang.wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fengyang.wang/32/104_2.png) [@fengyang.wang](https://discourse.julialang.org/u/fengyang.wang)
#### Post date: [April 13, 2017, 5:51am UTC](https://discourse.julialang.org/t/human-readable-but-precise-printing-of-data/2212/5 "2017-04-13T05:51:11Z")

</div>

I believe `repr(x)` (equivalent to `sprint(showall, x)`) and `showall(x)` are closer to what you want.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [July 14, 2017, 8:56am UTC](https://discourse.julialang.org/t/human-readable-but-precise-printing-of-data/2212/6 "2017-07-14T08:56:16Z")

</div>

To revive this topic: I have been using

```julia
showfull(io, x) = show(IOContext(io; compact = false, limit = false), x)
showfull(x) = showfull(STDOUT, x)

```

for a while. Would inclusion in `Base` make sense?
