[Python-ideas] namedlist() or Record type

Haoyi Li haoyi.sg at gmail.com
Wed Jul 24 16:41:31 CEST 2013


While we're on the subject of possible alternatives, I think macropy's case
classes <https://github.com/lihaoyi/macropy#case-classes> are a pretty nice
balance between namedtuple-ish concerns of conciseness, auto-{__str__,
__eq__, __init__, etc.} as well as class-ish concerns of being able to give
them methods and initializers, with a pretty nice (macro-powered) syntax.
It's a syntax that looks equally pretty whether you're writing a simple
Point(x, y) struct or a large-ish class with many members, initialization
logic and methods, which I think is pretty nice.


On Wed, Jul 24, 2013 at 9:28 PM, Eric V. Smith <eric at trueblade.com> wrote:

> On 07/24/2013 08:54 AM, Steven D'Aprano wrote:
> > On 24/07/13 17:50, anatoly techtonik wrote:
> >> Rationale: There are many 2D data with table layout where order is
> >> important and it is hard to work with them in Python.
> > [...]
> >
> > It sounds to me that what you want is a mutable namedtuple. At least,
> > that's what I often want. namedtuple was a fantastically useful addition
> > to the standard library, I think a mutable record type would be too.
>
> There are a number of implementations of this on PyPi, and probably
> elsewhere. Here's one I wrote:
>
> https://pypi.python.org/pypi/recordtype/
>
> It could use some polishing. I don't particularly like that it conflates
> mutability along with default parameters, but I couldn't think of an
> easy way to separate them, and for my particular use I needed both.
>
> Eric.
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130724/0d3a2f98/attachment-0001.html>


More information about the Python-ideas mailing list