I want to use python to parse the input to a simulation written in C. Right
now the simulation handles input by reading a table of constant values. I
envision using a python/C interface to improve the way my program handles
user input. From the python distribution documentation, I think I
understand how to add a python parser to a C program and how to add a C
function to python. I need help/advice on how to have my C program read the
value of the variables that were input in python (i.e., scan python's symbol
table for the desired variables).
This is a numerical simulation that has several dozen subroutines with
hundreds of input variables. The user only needs to explicitly set the
input variables that are changed from their default values. At the
beginning of a simulation run, each subroutine requiring input would have an
initialization section for each input variable. I will express the
functionality of what I think I want with the following pseudo-code:
/* initialize variables from python parser*/
x = py_is_var_defined("sub1_x") ? py_get_var_value("sub1_x") :
The input parsed by python would be normal python code with the variables of
interest defined and a call to the function that runs the simulation. After
completion of the simulation run, control would return to the python parser.
Are there python functions that provide the desired functionality for
reading the value of python variables into a C routine? I have checked the
FAQ and the python documentation, and I have not seen any direct mention of
how to do this. I would appreciate any help that you can give me.