En/na Andrew Straw ha escrit:: > Hmm... I still think it's a bug if getattr works but delattr fails by > raising an AttributeError. Some other kind of error would at least be > more understandable for setattr and delattr. I mean, the attribute > exists -- I can get it -- I just can't set it or delete it. So maybe a > TypeError or an AttributeNotModifiableError or something. > [...]
Hi Andrew, the exception you got and the behaviour you observed is
intentional. Group.__delattr__() does not remove children nodes because
it would be prone to accidental removal of whole subtrees. It only
removes standard Python attributes. That's why you got an error (there
was no standard Python attribute called *group*).
Natural naming is just a help for comfortably getting to nodes during
interactive, command-line sessions, and that's why it is only concerned
with Group.__getattr__(). __setattr__() and __delattr()__ are only
concerned with standard Python attributes, so you would be setting and
deleting standard attributes, not child nodes. To sum it up:
1. Group.__setattr__() always sets a Python attribute.
2. Group.__getattr__() gets a Python attribute, if available. Else, it
gets a child node.
3. Group.__delattr__() always deletes a Python attribute.
You can get more info in their respective docstrings.
Hope that helps. Greetings,
::
Ivan Vilata i Balaguer >qo< http://www.carabos.com/
Cárabos Coop. V. V V Enjoy Data
""
signature.asc
Description: OpenPGP digital signature
