On 28 Feb 2007 13:53:37 -0800, Luis M. González <[EMAIL PROTECTED]> wrote:
> Hmmm... not really.
> The code above is supposed to be a shorter way of writing this:
>
> class Person:
>     def __init__(self, name, birthday, children):
>         self.name = name
>         self.birthday = birthday
>         self.children = children
>
> So the purpose of this question is finding a way to emulate this with
> a single line and minimal typing.

I believe this is what you are looking for:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/361668

    olle = attrdict(name = "Olle", birthday = date(2222, 12, 1), children = 329)
    print olle.name, olle.birthday, olle.children

It is not identical to the Ruby recipe, but is IMHO better. Being able
to instantiate objects on the fly, without having to explicitly
declare the class, is a big advantage.

-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to