class declaration shortcut

Bjoern Schliessmann usenet-mail-0306.20.chr0n0ss at spamgourmet.com
Wed Feb 28 18:20:32 EST 2007


Luis M. González wrote:

> I've come across a code snippet in www.rubyclr.com where they show
> how easy it is to declare a class compared to equivalent code in
> c#. I wonder if there is any way to emulate this in Python.
> 
> The code is as follows:
> 
> Person = struct.new( :name, :birthday, :children)

What's easy about this?

Also, this is a definition and not just a declaration.

> But this above is not what I want.
> I guess I should find a way to include the constructor code inside
> this function, but I don't know if this is possible.

Could you please describe what exactly you want in an abstract way?

> Also, I wonder if there is a way to use the variable name in order
> to create a class with the same name (as in "Person"above).

Two classes with the same name?

In Python, classes have no name. They are anonymous objects which
can be bound to names.

Regards,


Björn

-- 
BOFH excuse #367:

Webmasters kidnapped by evil cult.




More information about the Python-list mailing list