[Python-ideas] Make-statement [Re: Different interface for namedtuple?]

Jan Kaliszewski zuo at chopin.edu.pl
Fri Mar 25 14:30:28 CET 2011


Hello,

Greg Ewing dixit (2011-03-06, 12:18):

> For Python, I postulated an "instance" statement that would
> be used something like this:
> 
>   instance Wardrobe(Thing):
> 
>     name = "wardrobe"
>     description = "A nice mahogany double-door wardrobe."
> 
>     def take(self):
>       print "The wardrobe is too heavy to pick up."

Why don't use a class decorator? E.g.:

    def instance(*args, **kwargs):
        return (lambda cls: cls(*args, **kwargs))

And then simply:

    @instance(...some init args...)
    class Wardrobe(Thing):
        ...

Cheers.
*j




More information about the Python-ideas mailing list