Thanks very much Bridget.
I often use add_component
in a loop. In those cases, I may want to give my components “names” dynamically based on a list.
I can use setattr
to accomplish this. Do you see any problems with this approach?
For example:
names=['a', 'b', 'c']
for n in names:
l=Link(text=n)
setattr(self, n, l) # assigning a new property based on a string
self.add_component(l)
# referencing by custom name
print(self.c.text)
# returns
'c'
The other thing is that, in a previous post, Ian mentioned that it was not a great idea to add arbitrary attributes onto a component (e.g., self.my_button.name='foo'
). Instead, he recommended to use the tag
property to store attributes.
Is it still recommended to use the tag property to store arbitrary attributes on components?