On 10 Jan 2007 14:46:54 -0800, Emin <[EMAIL PROTECTED]> wrote: >Dear Experts, > >When writing large classes, I sometimes find myself needing to copy a >lot of parameters from the argument of __init__ into self. Instead of >having twenty lines that all basically say something like self.x = x, I >often use __dict__ via something like: > >class example: > def __init__(self,a,b,c,d,e,f,g,h,i,j,k,l,m,n): > for name in >['a','b','c','d','e','f','g','h','i','j','k','l','m','n']: > self.__dict__[name] = locals()[name] > >This saves a lot of code and makes it easier to see what is going on, >but it seems like there should be a better idiom for this task. Any >suggestions?
I use a helper, like http://divmod.org/trac/browser/trunk/Epsilon/epsilon/structlike.py#L35 Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list