Hi,
I have a composite struct ABC
with various fields A
,B
,C
, which I want to display in a clear way on the screen (and later in Jupyter, but starting with REPL/console).
Here’s my code:
struct ABC
A::Vector{Int64}
B::Vector{Float32}
C::Vector{String}
end
abc = ABC(
[1,2,3],
[4.5, 6.7, 8.9],
["hello", "world"]
)
function Base.show(io::IO, x::ABC)
show(io,
"""
A:
$(x.A)
B:
$(x.B)
C:
$(x.C)
""")
end
println(abc)
However, it shows a string with “\n” rather than actual newlines:
"A:\n [1, 2, 3]\n\nB:\n Float32[4.5, 6.7, 8.9]\n\nC:\n [\"hello\", \"world\"]\n"
What am I missing?
Note: also tried PrettyPrint.jl and PrettyPrinting.jl but they seem to return similar output to print
for this case.