A Wednesday 04 June 2008, Swank, Craig escrigué:
> Hello,
> I would like to be able to make a base class that has some columns,
> and subclass that base class so I can inherit those columns, for
> example:
>
> import tables
>
> class A(tables.IsDescription):
>     x = tables.Int32Col()
>
> class B(A):
>     y = tables.Int32Col()
>
> inFile = tables.openFile('test.h5', mode="w")
> group = inFile.createGroup(inFile.root, 'group')
> table = inFile.createTable(group, 'table', B, 'a table')
>
> entry = table.row
>
> print  '\n', '*' * 20, 'column names', table.colnames, '*' * 20, '\n'
>
> entry['y'] = 0
> entry['x'] = 1
>
> inFile.close()
>
> When I run it I get this:
>
> cswank-09290s:test cswank$ python blah.py
>
> ******************** column names ['y'] ********************
>
> Traceback (most recent call last):
>   File "blah.py", line 18, in <module>
>     entry['x'] = 1
>   File "tableExtension.pyx", line 1294, in
> tableExtension.Row.__setitem__ File "tableExtension.pyx", line 130,
> in tableExtension.getNestedFieldCache File "utilsExtension.pyx", line
> 375, in utilsExtension.getNestedField KeyError: 'no such column: x'
> Closing remaining open files: test.h5... Done
>
>
> Is there a way to inherit columns from a superclass?

It doesn't seem so.  What are you trying to do?  Perhaps using 
dictionaries for defining the table structure may be handier.

Cheers,

-- 
Francesc Alted
Freelance developer
Tel +34-964-282-249

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Pytables-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to