YAML is a nice input file format that can be useful for using a file to set variables for a code.
import yaml
Basics
from IPython.display import IFrame
IFrame('http://ignite.byu.edu/che263/lectures/input.yaml', width=600, height=820)
import yaml
yfile = yaml.load(open("input.yaml"))
#--------- Read some nested vars:
seed = yfile["params"]["seed"] # seed is a variable in the params "nest"
tEnd = yfile["params"]["tEnd"] # grab tEnd, also in the params "nest"
print("seed = ", seed)
print("tEnd = ", tEnd)
y_O2 = yfile["streamProps"]["comp0"]["O2"] # grab O2 concentration (note the nesting)
print("O2 concentration = ",y_O2)
#---------- Load an array of data:
dumpTimes = yfile["dumpTimes"] # load the 1-D array (this is too easy!)
xydata = yfile["initParams"]["vprof"]
print("dumpTimes = ", dumpTimes)
print("xydata = ", xydata)
seed = 23 tEnd = 0.3682 O2 concentration = 0.21 dumpTimes = [1e-05, 0.01, 0.02, 0.021] xydata = [[-0.02104, 9.25], [-0.019988, 9.25], [-0.016832, 9.15], [-0.01315, 9.0]]