Closed Dominik1123 closed 1 year ago
But how can I retrieve the information that the parent command is
"base"
and the base command is"quadrupole"
?
are you looking for elem.parent.name
and elem.base_type.name
?
I would like get the commands that were used to create that element as strings.
that might not be possible exactly in full generality.
I realized that these are stored in the _attr instance attribute, but that doesn't seem to be part of the public API due to underscore prefix
If it contains what you need, I recommend to just use it anyway.As you know "private" in python just means that the developers reserve the possibility to change it between versions without prior notice, so you may have to change code when upgrading, but in this case it's unlikely to change anytime soon.
Thank you for the information. The .name
attribute seems to be what I need. I considered dir(m.elements['q01'])
and the docs for information on what's available, but name
isn't listed there, so that's why I ended up asking this question.
Okay. I guess the docs should be expanded to hint at what attributes might be available. Feel free to submit a PR.
Consider the following example
test.madx
script:I can get the element
q01
in the following way:The repr shows me that this element was created with command
base
. I can access this parent and the base viaparent
andbase_type
respectively:But how can I retrieve the information that the parent command is
"base"
and the base command is"quadrupole"
? I.e. for a given element I would like get the commands that were used to create that element as strings. I realized that these are stored in the_attr
instance attribute, but that doesn't seem to be part of the public API due to underscore prefix. So I wondered what is the preferred way to retrieve that information?