[Python-ideas] recorarray: a mutable alternative to namedtuple

Luciano Ramalho luciano at ramalho.org
Sat Mar 28 00:29:28 CET 2015


On Fri, Mar 27, 2015 at 8:13 PM, Andrew Barnert
<abarnert at yahoo.com.dmarc.invalid> wrote:
> So, if you want the equivalent of a C struct, there's no reason to make it an iterable in Python.

Yes, there is: iterable unpacking.

> Which is easy to do: just create a class, and create its fields in the __init__ method (or, in some cases, it's acceptable to use class attributes as "default values" for instance attributes).

Boilerplate with lots of repetition, with little added value. For
example, in a basic __init__ each attribute name usually occurs three
times: as an argument name in the method declaration, and then twice
when it's assigned to self. Ruby does much better, for example.

Best,

Luciano


More information about the Python-ideas mailing list