[Numpy-discussion] recarray field names

Erin Sheldon erin.sheldon at gmail.com
Wed Mar 15 12:21:04 EST 2006


Hi all-

I'm new to numpy and I'm slowly weening myself off of IDL. So far the
experience has been very positive.

I use recarrays a lot.  I often read these recarrays from fits files
using pyfits (modified to work with numpy).  I find myself doing the
following more than I would like:

if 'TAG' in rec._coldefs.names:
   ....

It seems messy to be accessing this "hidden" attribute in this way.
Is there a plan to add methods to more transparently do such things?

e.g.

def fieldnames():
   return _coldefs.names

def field_exists(fieldname):
   return fieldname.upper() in _coldefs.names

def field_index(fieldname):
   if field_exists(fieldname):
      return _coldefs.names.index(fieldname.upper())
   else:
      return -1  # or None maybe

Thanks,
Erin




More information about the NumPy-Discussion mailing list