Generic constructors and duplication of internal Python logic

Sebastien de Menten sdementen at hotmail.com
Thu Apr 29 03:13:58 EDT 2004


> > Here is a metaclass for uber-lazy user :-)
> > 
> > Concretely, at the creation of the class it takes the source of the
> > __init__ function and add, at the first line of __init__, the line
> > that sets the attributes :
> > >         self.foo, self.bar, self.baz, self.optional1, self.optional2 = 
> > >                    foo, bar, baz, optional1, optional2
> > 
> 
> Unfortunately this approach does not work if the source is not available
> (this happens when you are in the interpreter, or when you only have a .pyc 
> file). I was playing this kind of tricks some time ago, then I decided that
> it was best to switch to Lisp/Scheme for this kind of stuff ;)
> 
> 
>   Michele Simionato

I agree that it is quite low-level. However, 1) I think people are
"very" rarely creationg new classes directly in the interpreter (it's
a pain!) 2) I don't get the point about the .pyc (the metaclass is in
the pyc ? the class is in the pyc ?)
About the List/scheme option, it would be definitely way easier to do
it with macros in those languages but, hey, if i'm working with
python, i need a solutioon in python, don't I ?

Seb



More information about the Python-list mailing list