Mac wrote: >Is there a nice Python idiom for constructors which would expedite the >following? > >class Foo: > def __init__(self, a,b,c,d,...): > self.a = a > self.b = b > self.c = c > self.d = d > ... > >I would like to keep the __init__ parameter list explicit, as is, >rather than passing in a dictionary, as I want the code to be explicit >about what arguments it expects... in effect enforcing the right number >of arguments. > > I could list the parameter names programatically:
class A(object): def __init__(self,a,b,c,d,e,f,): varnames = self.__init__.im_func.func_code.co_varnames for varname in varnames[1:7]: print varname a = A(1,2,3,4,5,6) But I could not get their values. -- http://mail.python.org/mailman/listinfo/python-list