Custom printing of struct?

If I have a struct with some arbitrary values, how can I make a function, such that when I call “print” or “println” it will print the struct in the way I define?

Kind regards

1 Like

You can overload the Base.show(io::IO, obj::MyType) function.
Example:

4 Likes

See the manual on custom pretty printing.

3 Likes

Thanks to both of you :blush: Works as I want now!

Kind regards

1 Like

Also take a look at MechanicalRabbit/PrettyPrinting.jl: Julia library for optimal formatting of composite data structures (github.com)

2 Likes