Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code
Bengt Richter
bokr at oz.net
Mon Jul 4 00:38:38 EDT 2005
On Mon, 04 Jul 2005 02:50:07 GMT, bokr at oz.net (Bengt Richter) wrote:
>On Sun, 03 Jul 2005 22:07:30 GMT, Ron Adam <rrr at ronadam.com> wrote:
>
>>Bengt Richter wrote:
>>
>>
>>class foo(object):
>> x = 1
>> y = 2
>> z = 3
>> def __init__(self,x=x,y=y,z=z):
>> save_these = subdict(locals(),['x','y'])
>> self.__dict__.update(save_these)
> self.__dict__.update({'x':x, 'y':y, 'z':z}) # should work without save_these
oops, I see you only wanted x and y, so that should be
self.__dict__.update({'x':x, 'y':y}) # should work without save_these
>>
>> # rest of code
>> print self.x, self.y, self.z
>>
>>f = foo()
>>f = foo(5,6,7)
>>
Regards,
Bengt Richter
More information about the Python-list
mailing list