next up previous [pdf]

Next: String substitution Up: Integrating Python with SCons Previous: A forewarning

Variables

The most effective way to combine SCons and Python is to use Python to manage important variables for your scripts. For example, if you want to test a variety of values for a certain processing Flow, then you might save the value to a variable and then let Python format it correctly for you, instead of changing the string each time you want to run a new test. You can also save all your variables in a convenient location and then easily change them to test different parameters as well. For example:


\begin{verbatimtab}[4]
nx = 100
nz = 100
\par
Flow('model',None,
'''sfspike n1='''+str(nx)+'''n2='''+str(nz))
\end{verbatimtab}
Note: variables must be converted to strings in order to be combined into the command statements. Because these variables are converted using string concatenation, there is a possibility that a user could give a value of a wrong type.




2011-11-03