[Numpy-discussion] numarray.records - get/set item

Perry Greenfield perry at stsci.edu
Thu Dec 4 15:09:09 CST 2003


> Hi,
> Is it maybe a good idea to add this to the definition of 'class Record'
>
> class Record:
>     """Class for one single row."""
> <snip>
>     def __getitem__(self, fieldName):
>         return self.array.field(fieldName)[self.row]
>     def __setitem__(self, fieldName, value):
>         self.array.field(fieldName)[self.row] = value
>
> I don't know  about the implications if  __delitem __  and so on are not
> defined.
> I just think it would look quite nice to say
> myRecArr[0]['mmm'] = 'hallo'
> as opposed to
> myRecArr[0].setfield('mmm',  'hallo')
>
> Actually I would even like
> myRecArr[0].mmm = 'hallo'
>
> This should be possible by defining __setattr__.
> It would obviously only work for fieldnames that do not contain '.' or ' '
> or ...
>
> Any comments ?
>
>
We've had many internal discussions about doing this. The latter was
considered a problem because of possible name collisions of field
names with other attributes or methods. The former is not bothered
by this problem, but we decided to be conservative on this and see
how strong the need was. We are interested in other opinions.

Perry





More information about the Numpy-discussion mailing list