I'm trying to get rid of exec
in a code similar to this:
class A(object):
for field in ['one', 'two', 'three']:
exec '%s = "%s value"' % (field, field)
...so that:
>>> A.one
'one value'
>>> A.two
'two value'
>>> A.three
'three value'
EDIT: and also the requirement mentioned in the subject is met i.e. A.one
is 'one value'
, before A
is instantiated (not to be mistaken for A()
instantiated).
Is there a way?