I have a struct defined as follows:
julia> struct test
test1::Int64
test2::Float64
end
I want to be able to see the names of the attributes in the struct as well as the type. What is the most straight forward way to do this? I know I can do:
julia> t = test(1,1.0)
test(1, 1.0)
julia> fieldnames(typeof(t))
(:test1, :test2)
but I would like to see the attribute name and type together.
Use fieldtypes(typeof(t))
julia> DataFrame(name=[fieldnames(typeof(t))...], type=[fieldtypes(typeof(t))...])
2×2 DataFrame
│ Row │ name │ type │
│ │ Symbol │ DataType │
├─────┼────────┼──────────┤
│ 1 │ test1 │ Int64 │
│ 2 │ test2 │ Float64 │
Regarding the other answer note that dump outputs always the entire data structure which is not good for fields having complex types. Try doing dump on a struct that has a Dict field to find out my point (or just try in the console) dump(Dict()).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With