exec
Rolf Wester
rolf.wester at ilt.fraunhofer.de
Thu Mar 1 10:58:41 EST 2012
Hi,
thanks for your replies so far.
The reason to use exec is just laziness. I have quite a lot of classes
representing material data and every class has a number of parameters.
The parameter are Magnitude objects (they have a value and a unit and overloaded
special functions to correctly handle the units). I want to have getter
functions that either return the Magnitude object or just the value:
iron = Iron()
iron.rho(0) => value
iron.rho() => Magnitude object
def rho(self, uf=1):
if uf == 1:
return self._rho
else:
return self._rho.val
And because this would mean quite a lot of writing I tried to do it with exec.
With kind regards
Rolf Wester
More information about the Python-list
mailing list