idiom for constructor?
Laszlo Zsolt Nagy
gandalf at geochemsource.com
Wed Jun 1 15:29:01 EDT 2005
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.
More information about the Python-list
mailing list