From: Ivan V. i B. <iv...@ca...> - 2005-10-18 14:28:56
|
En/na Norbert Nemec ha escrit:: > Ivan Vilata i Balaguer wrote: >>The motto you quote was in fact what prevented me from accepting one >>more interface. But if we were to make groups more dictionary-like, >>then the ``getChild()``-like interface would be the one out of place! ;= ) >> >>So, do you see advantages in the dictionary-like interface? >=20 > Well, why not? It could be made clear that __get/setitem__ and > __get/setattr__ are basically the same thing, accessing the children of= > any node, except that item will use the unquoted original name from > HDF5, while attr will quote the name in the style that you propose. >=20 > For HDF5-Attributes, the behavior should be the same, except that it > does not work on node itself, but on node.attrs. >=20 > In general, use of operators should be handled with care, but in this > case, since accessing and setting the children of a node is the one > major purpose of any group, it makes sense to give it this special synt= ax. >=20 > Of course, get/setChild should then go away, or at least its use should= > be discouraged. Francesc and I have been giving this issue a thought, and some problems have immediately come to mind. In the first place, as you say, some operators would not make sense or they would be ambiguous, e.g. does ``del group[childgroup]`` act recursively or not? Does ``for n in group`` yield names of nodes or nodes themselves? Does it recurse? What does ``group.pop()`` mean? How do you rename a child node? Some of the previous ambiguity goes away by using more descriptive methods, but hen we end up implementing half a dictionary interface with lots of extra methods to complete it. Maybe there's no point in making groups dictionary-like, then. But maybe it's OK to implement only a part of the dictionary interface. In the second place, leaves will also have their own, very differently behaving item interface, so having an item interface for leaves and groups may get confusing. Now, I know we seem to oscillate from one side to the other one with this question; maybe we need the ultimate advice! ;) :: Ivan Vilata i Balaguer >qo< http://www.carabos.com/ C=C3=A1rabos Coop. V. V V Enjoy Data "" |