2013-10-11 22 views
0

是否有任何方法來遍歷表元對象的字段? (不是表本身,我需要做一些初步分析,甚至在表甚至實例化之前)獲取有關pytables元數據的信息

我對Python中的元類並不熟悉,所以這對我來說是神祕的東西。

class Particle(IsDescription): 
    name  = StringCol(16, pos=1) # 16-character String 
    lati  = IntCol(pos=2)  # integer 
    longi  = IntCol(pos=3)  # integer 
    pressure = Float32Col(pos=4) # float (single-precision) 
    temperature = FloatCol(pos=5)  # double (double-precision) 

回答

1

該類的columns屬性是一個字段,列名爲數據類型值的鍵。然後,您應該能像遍歷Python字典(鍵(),values(),items()等)一樣遍歷此字典。

In [7]: Particle.columns 
Out[7]: 
{'lati': Int32Col(shape=(), dflt=0, pos=2), 
'longi': Int32Col(shape=(), dflt=0, pos=3), 
'name': StringCol(itemsize=16, shape=(), dflt='', pos=1), 
'pressure': Float32Col(shape=(), dflt=0.0, pos=4), 
'temperature': Float64Col(shape=(), dflt=0.0, pos=5)}