From: Ivan V. i B. <iv...@ca...> - 2005-01-24 09:12:53
|
Hi all! There has been quite a lot of discussion on the topics of natural naming, __getattr__ vs. __getitem__ and unbound nodes on the last week. Since verbal descriptions seem to be incomplete most of the time, or simply misleading, I've decided to make a sample implementation as a proof of concept for those topics. Basically, the attached code does: * define a new Node class from which Group and Leaf inherit. * allow nodes to be created unbound and then be bound to a group by simple assigning. Nodes are not allowed to handle data while unbound, but a partial hierarchy can be built using unbound nodes (this last feature might be more difficult to implement in PyTables). * allow quasi-arbitrary node names in a group. They can always be accessed using __{get,set,del}item__, also using __{get,set,del}attr__ if they match natural naming conventions. * put every group child name in its __dict__, to allow the user to see all possibilities on completion (although some of them may actually be not accessed using dot notation). * only allow Node objects in a Group. Please try to read the whole code. It is quite straightforward and simple. Don't be frightened by its length, there's a lot of blank lines in there. ;) Hope this helps to clarify some things. Of course, suggestions are accepted. Regards, Ivan import disclaimer -- Ivan Vilata i Balaguer >qo< http://www.carabos.com/ Cárabos Coop. V. V V Enjoy Data "" |