Module nestedrecords :: Class NestedRecord
[show private | hide private]
[frames | no frames]

Class NestedRecord

Record --+
         |
        NestedRecord


Nested record.

This is a generalization of the numarray.records.Record class to support nested fields. It represents a record in a NestedRecArray or an isolated record. In the second case, its names are automatically set to c1, c2 etc. on each nested field.

This class is compatible with Record. However, getting a field may return a NestedRecord instead of a Python scalar, NumArray or CharArray, if the field is nested.

Fields and sub-fields can be accessed using both the field() method and the fields interface, which allows accessing fields as Python attributes: nfld = nrec.fields.f1.fields.subf1[4]. The field() method supports the '/' separator to access sub-fields.

Nested recors can be converted to ordinary records by using the asRecord() method.


Method Summary
  __init__(self, input, row)
  asRecord(self)
Convert a nested record to a non-nested equivalent record.
  field(self, fieldName)
Get field data.
  setField(self, fieldName, value)
Set field data.
    Inherited from Record
  __str__(self)
Print one row.
  setfield(self, fieldName, value)
Set the field data of the record.

Method Details

asRecord(self)

Convert a nested record to a non-nested equivalent record.

This function creates a new vanilla Record instance equivalent to this one by flattening its fields. Only bottom-level fields are included in the array.

The data area of the record is copied into the new one.

Example

Let us take the following nested record:

>>> nr = NestedRecord([1, (0, 0), ('a1', 1j)])

Calling nr.asRecord() would return the same record as calling:

>>> r = numarray.records.Record([1, (0, 0), 'a1', 1j])

Please note that the shape of multi-dimensional fields is kept.

field(self, fieldName)

Get field data.

If the named field (fieldName, a string) is not nested, a Python scalar, NumArray or CharArray object with the value of that field is returned. Else, a NestedRecord object is returned.

fieldName can be used to provide the name of sub-fields. In that case, it will consist of several field name components separated by the string '/'. For instance, if there is a nested field named x with a sub-field named y, the last one can be accesed by using 'x/y' as the value of fieldName.

Overrides:
numarray.records.Record.field

setField(self, fieldName, value)

Set field data.

Sets the field indicated by fieldName (a string) to the given value. The structure of the value must match that of the field.

fieldName can be used to provide the name of sub-fields, as described in NestedRecord.field().


Generated by Epydoc 2.1 on Thu Apr 21 13:11:49 2005 http://epydoc.sf.net