0

Is there any way to iterate over the fields of a table metaclass object? (NOT the table itself, I need to do some preliminary analysis before a table is even instantiated)

I'm not really familiar with metaclasses in Python, so this is mystery stuff to me.

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)
Jason S
  • 184,598
  • 164
  • 608
  • 970

1 Answers1

1

The columns attribute on the class is a dictionary of column named keys to the data type values. You should then be able to iterate over this dictionary like you would any Python dictionary (keys(), values(), items(), etc).

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)}
Anthony Scopatz
  • 3,265
  • 2
  • 15
  • 14