A Wednesday 11 May 2011 04:55:22 Curiouslearn escrigué:
> Hello,
>
> Can someone please tell me if it is possible to iterate over user
> defined attributes of a table and print them out? Basically, I am
> looking to get the same information that results from:
>
> sometable.attrs
>
> except that
>
> (1) the above command also contains system attributes, which I don't
> want. (2) I want to format the attribute name and its value in a
> different manner than the above command yields.
>
> I tried the following code. This code does not work, but gives an
> idea about what I need.
>
> for i in sometable.attrs._f_list():
> print "{0} = {1}".format(i, sometable.attrs.i)
>
> The problem is that sometable.attrs.i does not return value of the
> attribute, whose name is represented by i in any given iteration. I
> want to go over the list of attributes and print their value.
>
Attributes cannot be accessed as normal class attributes, but as
elements of a mapping type:
for i in sometable.attrs._f_list(attrset='user'):
print "{0} = {1}".format(i, sometable.attrs[i])
See:
http://www.pytables.org/docs/manual/ch04.html#AttributeSetClassDescr
for a rational on why PyTables has chosen the 'getitem' getter instead
of the 'getattr'.
Hope this helps,
--
Francesc Alted
------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Pytables-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pytables-users