1. ericvsmith
  2. recordtype
Issue #3 new

Add Support for indexing

Timothy Wiseman
created an issue

Adding support for indexing by adding:



def getitem(self, index): return getattr(self, self.slots[index])

def setitem(self, index, value): return setattr(self, self.slots[index], value) }}}

to the class definitions would make it closer to a mutable namedtuple since namedtuple supports indexing.

Comments (6)

  1. ericvsmith repo owner

    Do you have some particular use case for this? It's my experience that indexing namedtuple's has caused me a bug or two, and I've never actually wanted the feature.

  2. Jakub Stasiak

    +1, one use case would be replacing plain tuples/lists with recordtype-based types and having existing, legacy code handle it without major modifications.

  3. kovalevfm

    Msgpack doesn't work without getitem . This code fails for exapmle:

    from recordtype import recordtype
    import msgpack
    Record = recordtype('Record', "a b")
    s = msgpack.packb(Record(a=1, b=2))
  4. Log in to comment