arguments of a function/metaclass

Gabriel Genellina gagsl-py at yahoo.com.ar
Tue Jan 16 18:03:01 CET 2007


"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 





More information about the Python-list mailing list