I want to be able to access and change an element of a structure based off a string that has been read in from a text file and then change the value of that element. The element that is being changed could of several different data types. A simplified version of the structure I am working with is shown below:
mutable struct SMALLSTRUCTURE
mutable struct BIGSTRUCTURE
julia> mutable struct SMALLSTRUCTURE
julia> t = SMALLSTRUCTURE(fill(1, 7)...);
julia> setproperty!(t, Symbol("SEEDMIN"), 100)
SMALLSTRUCTURE(1, 1, 100, 1, 1.0, 1.0, 1.0)
You want to use
setproperty!. Note that you have to use
setproperty!, so I convert the string to a
My issue with this though is that the string would be “SMALLSTRUCTURE.SEEDMIN” and setproperty!(Symbol(SMALLSTRUCTURE),Symbol(SEEDMIN),5) does not work so how can I also read in the name of the strucutre based off of the input string.
SMALLSTRUCTURE is the name of the type. You need an instance of that type, the
t in that example above.
You should store the variables in that you need to change in a
Dict which you can access with a
String key, rather than trying to use a string to look up variables in the global scope
Wait so are you saying that I should not use a structure to store all of my data
and just use a Dict?
And would it not be possible to pass in t as the string?
Is the input saying "If
x is a
SMALLSTRUCTURE, then update it’s