For v0.7+
Use fieldnames(x)
, where x
is a DataType
. For example, use fieldnames(Date)
, instead of fieldnames(today())
, or else use fieldnames(typeof(today()))
.
This returns Vector{Symbol}
listing the field names in order.
If a field name is myfield
, then to retrieve the values in that field use either getfield(x, :myfield)
, or the shortcut syntax x.myfield
.
Another useful and related function to play around with is dump(x)
.
Before v0.7
Use fieldnames(x)
, where x
is either an instance of the composite type you are interested in, or else a DataType
. That is, fieldnames(today())
and fieldnames(Date)
are equally valid and have the same output.
x
, typex.
(that'sx
followed by a dot.
) and then hit TAB once or twice. that asks Julia to autocomplete the command. Julia will then show you the fields ofx
, assuming that it has any. – Kevin L Keys