[Python-ideas] Add recordlcass to collections module

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Sep 2 19:09:54 EDT 2018

Zaur Shibzukhov wrote:

 > `Recordclass` is defined on top of` memoryslots` just like `namedtuple`
 > above` tuple`. Attributes are accessed via a descriptor (`itemgetset`),
 > which supports both` __get__` and `__set__` by the element index.
 > As a result, `recordclass` takes up as much memory as` namedtuple`, it
 > supports quick access by `__getitem__` /` __setitem__` and by attribute
 > name via the protocol of the descriptors.

I'm not sure why you need a new C-level type for this. Couldn't you
get the same effect just by using __slots__?


class C:

      __slots__ = ('attr_1', ..., 'attr_m')

      def __new __ (cls, attr_1, ..., attr_m):
          self.attr_1 = attr_1
          self.attt_m = attr_m


More information about the Python-ideas mailing list