[Numpy-discussion] Record arrays

Robert Kern robert.kern at gmail.com
Thu Jun 26 22:36:38 EDT 2008


On Thu, Jun 26, 2008 at 21:24, Gael Varoquaux
<gael.varoquaux at normalesup.org> wrote:
> I understand all your comments and thank you for making this distinction
> explicit. I can see why recarray can slow code down, but I find attribute
> lookup make code much more readable, and interactive work fantastic (tab
> completion).

I'm confused. recarray fields do not show up in any standard
tab-completion schemes.

> For many of my applications I do have a strong use case for
> these recarrays, and I am willing to take the speek cost (many of the
> things I do are very for from being numerically intensiv).
>
> On a side note, a pattern I use a lot (and incidently that Fernando and
> Brian also came up with in ipython1) is a mixed object that acts like a
> dictionary (and thus comes with all the goodies like the keys, iterkeys,
> ... methods, and the "in"), but exposes its keys as attributes:
>
> class Bunch(dict):
>
>    def __init__(self, **kwargs):
>        dict.__init__(self, **kwargs)
>        self.__dict__ = self
>
> a = Bunch(a=1, b=2)

Actually, I wrote that particular snippet in the IPython codebase, but
the idea comes from a Cookbook entry:

  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52308

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 -- Umberto Eco



More information about the NumPy-Discussion mailing list