finesse.model.Model.get_element¶
- Model.get_element(value)[source]¶
Returns an element in this model that matches the requested value. This input can be either a string name or an element that might be owned by another model. In the latter case the name attribute will be extracted from the value and a search done in this model for an equivalent element.
- Parameters
- value[str|`Element`]
Name or equivalently named Element object to extract from this model.
- Raises
- KeyError when element cannot be found or FinesseException when the
- input value cannot be used.
Examples
>>> import finesse >>> model = finesse.Model() >>> model.parse(''' ... l l1 P=1 ... l l2 P=2 ... ''') >>> model.get_element('l1'), model.get_element('l2') (<'l1' @ 0x122cf9fa0 (Laser)>, <'l2' @ 0x122cf9f40 (Laser)>)
Creating a copy of the model and getting elements will return elements with the same name but different id.
>>> model2 = model.deepcopy() >>> model2.get_element('l1'), model2.get_element('l2') (<'l1' @ 0x122d35c10 (Laser)>, <'l2' @ 0x122d35df0 (Laser)>)
Now if we try and select l1 using an element from a different model we should get the correct element with name l1 from that model
>>> model.get_element(model2.l1) <'l1' @ 0x122cf9fa0 (Laser)> >>> model2.get_element(model.l1) <'l1' @ 0x122d35c10 (Laser)>