[Python-ideas] Docstrings for namedtuple
Chris Rebert
pyideas at rebertia.com
Sun Dec 16 15:49:12 CET 2012
> On Sun, Dec 16, 2012 at 3:06 PM, Joao S. O. Bueno <jsbueno at python.org.br>
> wrote:
>> On 16 December 2012 11:24, Eli Bendersky <eliben at gmail.com> wrote:
>>>> This may be a good time to say that personally I always disliked
>>>> namedtuple's creation syntax. It is unpleasant in two respects:
>>>>
>>>> 1. You have to repeat the name
>>>> 2. You have to specify the fields in a space-separated string
>>>>
>>>> I wish there was an alternative of something like:
>>>>
>>>> @namedtuple
>>>> class Point:
>>>> x = 0
>>>> y = 0
>>>>
>>>
>>> And to the point of Serhiy's original topic, with this syntax there would
>>> be no need to invent yet another non-standard way to specify things like
>>> docstrings.
>>
>>
>> While we are at it,
>> why nto simply:
>>
>> class Point(namedtuple):
>> x = 0
>> y = 0
>>
>> ?
>>
On Sun, Dec 16, 2012 at 6:39 AM, Laurens Van Houtven <_ at lvh.cc> wrote:
> Err, can class bodies ever be order-sensitive?
Yep. You just have to define a metaclass with a __prepare__() that
returns an OrderedDict (or similar).
http://docs.python.org/3.4/reference/datamodel.html#preparing-the-class-namespace
http://docs.python.org/2/library/collections.html#ordereddict-objects
Cheers,
Chris
--
http://rebertia.com
More information about the Python-ideas
mailing list