arguments of a function/metaclass
goodwolf
Robert.Katic at gmail.com
Tue Jan 16 12:36:15 EST 2007
Gabriel Genellina je napisao/la:
> "goodwolf" <Robert.Katic at gmail.com> escribió en el mensaje
> news:1168964835.087773.221950 at s34g2000cwa.googlegroups.com...
> > A simply solution:
> >
> > def __init__(self, a=1, b=2, c=3, ......):
> > for key, val in locals().items():
> > if key != 'self':
> > setattr(self.__class__, key, val)
> >
> > in addition:
> >
> > def set(self, **kwarg):
> > for key in kwargs:
> > if hasattr(self.__class__, key):
> > setattr(self.__class__, key, kwargs[key])
> > else:
> > raise ....
>
> Why setattr(self.__class__,...) instead of setattr(self, ...)? You're
> modifying the class attributes, and that's not usually intended.
>
> --
> Gabriel Genellina
My error. Post was written directly. Sorry.
More information about the Python-list
mailing list