I use python mostly as glue-language for numerical simulations.
Typically I create some wrapper class which initialize some reasonable default parameters, and than elsewhere in larger script I call run()
method which optionally overrides some parameters and than executes the actual simulation.
It could look something like this:
class MyCalculationClass():
def __init__():
# set some defaults
self.A = 45454
self.B = np.zeros(16,11)
self.C = (1.0,2.5,30.0)
def runRaw():
return whatever(self.A,self.B,self.C)
def run( A=None, B=None, C=None ):
# optionally override some defaults
if A is not None:
self.A = A
if B is not None:
self.B = B
if C is not None:
self.C = C
# run the actual calculation
return self.runRaw()
mycalc1 = MyClaculationClass()
# .... Over the Hills and Far Away
mycalc1.run(B=np.zeros(11,12) )
but I really hate the boilerplate if A is not None: self.A = A
everywhere. Typically there are tens of parameters.
This would be slightly nicer
def run( A=self.A, B=self.B, C=self.C ):
# optionally override some defaults
self.A = A
self.B = B
self.C = C
# run the actual calculation
self.runRaw()
but:
- it does not work
- still it is too much boilerplate
NOTE: I really want self.A
etc. to keep being stored as class property in order to be able to recover which parameters I used in which calculation later in the larger script