Francesc Altet wrote:

A Dimecres 26 Abril 2006 00:21, Andrew Straw va escriure:
Hi, the following program fails:

import tables

class Info2D(tables.IsDescription):
   colA = tables.Int32Col(pos=0)
   colB = tables.Int32Col(pos=1)

h5file = tables.openFile('test.h5',mode='w')
group = h5file.createGroup( h5file.root, 'group' )

print getattr( h5file.root, 'group' )
delattr( h5file.root, 'group' )

The exact output is:

/group (Group) ''
Traceback (most recent call last):
 File "test_del_group.py", line 11, in ?
   delattr( h5file.root, 'group' )
 File "build/bdist.linux-i686/egg/tables/Group.py", line 794, in
__delattr__
AttributeError: group
Closing remaining opened files...  test.h5... done.

This is the expected behaviour. From the manual:

"""
This (Group) class defines the __setattr__, __getattr__ and __delattr__
methods, and they set, get and delete ordinary Python attributes as
normally intended. In addition to that, __getattr__ allows getting
child nodes by their name for the sake of easy interaction on the
command line, as long as there is no Python attribute with the same
name.
"""
(http://www.pytables.org/docs/manual/x2546.html)

So, you have to distinguish between child nodes and actual attributes
of a node. As the documentation says, the only reason why __getattr__
retrieves a child node is in order to ease interation on the command
line.

In any case, the standard way to delete a node is:

h5file.removeNode('/group')


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.

Still coming to grips with Nodes, Groups, and "actual attributes of a node",
Andrew


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Pytables-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to