[Python-ideas] Make-statement [Re: Different interface for namedtuple?]
greg.ewing at canterbury.ac.nz
Sun Mar 6 00:18:04 CET 2011
Carl M. Johnson wrote:
> make NamedTuple(rename=True) Point:
> x, y
> make Table() Author:
> firstname, lastname, DOB = Str(), Str(), Date()
I did some thinking about this kind of thing once when I was
considering Python as a language for interactive fiction. When
writing IF, you tend to have a lot of unique objects with
special behaviour, and to support this, dedicated IF languages
such as TADS usually have a construct that's somewhere between
a class declaration and an instantiation.
For Python, I postulated an "instance" statement that would
be used something like this:
name = "wardrobe"
description = "A nice mahogany double-door wardrobe."
print "The wardrobe is too heavy to pick up."
What this would do is first create an anonymous subclass of
Thing, and then instantiate that subclass.
This isn't quite what we're after here, though, because for
use cases such as namedtuple, we don't usually want a subclass,
and we *do* usually want to pass parameters to the constructor.
We'd also like it to fit on one line in simple cases.
It's hard to come up with a syntax that incorporates all of
these possibilites at the same time without becoming rather
long and confusing. The base class list and the construction
parameters both want to go in parentheses, and how do you
make it obvious which is which?
More information about the Python-ideas