[Python-ideas] anonymous object support
jeanpierreda at gmail.com
Sun Aug 7 00:53:21 CEST 2011
My favorite declarative-namedtuple hack is
On Sat, Aug 6, 2011 at 3:50 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> On 8/6/2011 2:53 AM, Eric Snow wrote:
>> On Sat, Aug 6, 2011 at 12:37 AM, Carl Matthew Johnson
>> <cmjohnson.mailinglist at gmail.**com <cmjohnson.mailinglist at gmail.com>>
>>> As another example, using metaclasses you can change namedtuple's syntax
>>> from the somewhat clunky
>>> Point = namedtuple('Point', 'x y')
>>> to the more elegant but confusing since it uses "class"
>>> class Point(NamedTuple):
> If NamedTuple were documented as having a custom metaclass, and if this
> were a common idiom, that would not be too confusing as all.
> You don't even need to use __prepare__() if you make it look like this:
>> class Point:
>> x = ...
>> y = ...
>> Since Ellipsis became valid as a normal-use object this works. And
>> that decorator is a snap to write.
> This looks ok to me too. New keywords and syntax should be *very* rare and
> reserved for things that cannot be done so easily with what we have now.
> Terry Jan Reedy
> Python-ideas mailing list
> Python-ideas at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas