class declaration shortcut
- From: "Luis M. González" <luismgz@xxxxxxxxx>
- Date: 28 Feb 2007 11:26:41 -0800
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)
I tried something like this, but it's nothing close to what I'd like:
def klass(table, *args):
cls = new.classobj(table, (), {})
for i in args:
setattr(cls, i, i)
return cls
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.
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).
Well, if anyone has an idea, I'd like to know...
Luis
.
- Follow-Ups:
- Re: class declaration shortcut
- From: Steven Bethard
- Re: class declaration shortcut
- From: Bruno Desthuilliers
- Re: class declaration shortcut
- Prev by Date: Re: Question about raise and exceptions.
- Next by Date: Re: finding out the precision of floats
- Previous by thread: Question about raise and exceptions.
- Next by thread: Re: class declaration shortcut
- Index(es):