[Python-ideas] recorarray: a mutable alternative to namedtuple
Joao S. O. Bueno
jsbueno at python.org.br
Sat Mar 28 02:45:38 CET 2015
On 27 March 2015 at 22:09, Andrew Barnert
<abarnert at yahoo.com.dmarc.invalid> wrote:
> Of course it's trivial to wrap up that boilerplate if you're going to create 20 of these. And to add in other functionality that C structs (and, except for the first, Python namedtuples) don't have that your project needs, like a nice repr, default values, runtime type checking, a JSON serialization schema, an ORM mapping, an HTML form representation, etc.
So -that is the point - it is trivial to do away with the boiler
plate, as I've shown on the other message, - but there is no way to
do it in the stdlib, so it is a wheel that is reinvented everytime.
NamedTuples are a way to do _almost_ that: make it tirvial to create a
class with only this fixed set of attributes, with as little
boilerplate as one can think of - but one can't change the attributes
on an instance of it.
That is why the start of the thread is about a "mutable named tuple" -
not because it is a tuple - but because it creates a basic class with
fixed attributes that works nicely, with minimal boiler plate.
Rethinking at my example, I think it does fit exactly in "too small to
be an external dependence in itself, and with too many subtle
behaviors to get done right again and again in several projects".
js
-><-
More information about the Python-ideas
mailing list