有任何方法来迭代表元类对象的字段吗?(不是表本身,我需要在表实例化之前进行一些初步分析)
我不太熟悉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)发布于 2013-10-12 18:16:12
类上的列属性是列的字典,列名为数据类型值的键。然后,您应该能够像遍历任何Python字典一样遍历该字典(key()、value()、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)}https://stackoverflow.com/questions/19328235
复制相似问题