python - How can I define a nested node structure using the same type for parent and child in PyTables? -


based on pytables documentation, appears way define nested types either create class level/static field nested type instance or define nested class in parent class.

the problem is, common tree representation uses node type child node instances. normally, not problem python class since dynamic typing not force me define type of child(ren), , @ runtime, node instance can added node instance child.

pytables on other hand, requires type of field defined. since class definition in python can't used in class level field initialization, common way of parent - child structure definition becomes unavailable. not sure if constraint exists @ hdf5 level though (did not check). here example of problem:

class a(isdescription):     valstring = stringcol(250, pos=1)     child = a()# impossible   class a(isdescription):     valstring = stringcol(250, pos=1)     #the following work, can't define     #another achild child, got stuck depth 1     class achild(isdescription):         valstring = stringcol(250, pos=1)         class anewchild(isdescription):             valstring = ....#useless 

i have data fits type node node children definition, , can't represent pytables @ moment. there trick i'm missing?

a table not right place put recursive structures. try if can want using group tree. since works analogous directories , subdirectories, may solve problem. can put subgroups , tables 1 group. in addition can use attributes groups. allows store shorter strings , such.

this has nothing pytables. try in pure python

>>> class a(object): ...     = a() ...  traceback (most recent call last):   file "<stdin>", line 1, in <module>   file "<stdin>", line 2, in nameerror: name 'a' not defined 

you cannot use name not defined yet. likely, think this:

>>> class a(object): ...     def __init__(self): ...         self.a = a() 

no problem here. difference in frist case have class variable , in second instance variable. while a = a() executed when python complies source code, self.a = a() executed when make instance of a, i.e. @ run time.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -