[Python-ideas] A mutable alternative to namedtuple

Zaur Shibzukhov szport at gmail.com
Thu Mar 19 08:04:38 CET 2015



вторник, 17 марта 2015 г., 20:21:01 UTC+3 пользователь Eric V. Smith 
написал:
>
> On 03/17/2015 12:52 PM, Luciano Ramalho wrote: 
> > Sometimes we need a simple class to hold some mutable attributes, 
> > provide a nice repr, support == for testing, and support iterable 
> > unpacking, so you can write: 
> > 
> >>>> p = Point(3, 4) 
> >>>> x, y = p 
> > 
> > That's very much like the classes built by namedtuple, but mutable. 
>
> https://pypi.python.org/pypi/namedlist 
>
> It also adds default values to the generated constructor, which may or 
> may not be desirable. But if used exactly like collections.namedtuple, 
> it ignores the default values. 
>
> Eric. 
>
> Since named tuple is considered as an object that is a tuple with 
attribute access. 
The mutable alternative could be considered as an array with attribute 
access.
Array in this context is tuple-like object that support assign operation.
Since python have not such object there are different approaches tomutable  
named tuple alternatives.

One should note that particular property of named tuple is memory saving.
So one can expect similar property of mutable named tuple too.
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150319/8342986a/attachment-0001.html>


More information about the Python-ideas mailing list