idiom for constructor?
Peter Dembinski
pdemb at gazeta.pl
Sat Jun 4 12:18:26 EDT 2005
Steven Bethard <steven.bethard at gmail.com> writes:
> Peter Dembinski wrote:
>>class A:
>> def __init__(self, a, b, c, d):
>> initial = {'a' : a, 'b' : b, 'c' : c, 'd' : d}
>> for param in initial.keys():
>> exec "self.%s = initial['%s']" % (param, param)
>
> This is not a good use case for exec. Use setattr:
OK, true.
>From the other side: what are the usual uses of 'exec'?
More information about the Python-list
mailing list