calsaverini
May 24th, 2008, 07:07 PM
Hi,
I'm new to python and not a very skilled programmer in C as well. But I need to create from scratch a program to analyze some data I have for my doctoring thesis so I need to do this.
I have already made a program in C that receive the data in command line like this:
./my_cute_program x1 x2 x3 ... xN
where x1, x2, etc... are the needed data.
The program used to be run from a bash script that got the data from a mysql database and made the above call to the program.
But then, the script where soooo slow for tests I needed to run (it took like half an hour to generate some 10³ gaussian random numbers and send them to the C program) that I decided to use a very simple Python program to do this.
The Python program simply generate a string with the data:
S = " x1 x2 ... xN"
and called the C program via the os.system command:
os.system('./my_cute_program'+S)
Until now I was only looking to the text output of the C program so I had no problem with any C/Python integration (I just didn't needed it). But now I need to run some automated tests for many many runs of the C program, make histograms and such. So I need the python program to read variables from the C program.
My questions are:
1) Is there a way that my Python program can read variables from the C program when the later finish its run?
2) Is there a more intelligent way to call the C program from python? The method I use above is just make a call to the OS. It seems to me a dumb way to do it. Is there a way I can call maybe the main() function of my C program from inside python or something like that?
-
Thanks for helping.
I'm new to python and not a very skilled programmer in C as well. But I need to create from scratch a program to analyze some data I have for my doctoring thesis so I need to do this.
I have already made a program in C that receive the data in command line like this:
./my_cute_program x1 x2 x3 ... xN
where x1, x2, etc... are the needed data.
The program used to be run from a bash script that got the data from a mysql database and made the above call to the program.
But then, the script where soooo slow for tests I needed to run (it took like half an hour to generate some 10³ gaussian random numbers and send them to the C program) that I decided to use a very simple Python program to do this.
The Python program simply generate a string with the data:
S = " x1 x2 ... xN"
and called the C program via the os.system command:
os.system('./my_cute_program'+S)
Until now I was only looking to the text output of the C program so I had no problem with any C/Python integration (I just didn't needed it). But now I need to run some automated tests for many many runs of the C program, make histograms and such. So I need the python program to read variables from the C program.
My questions are:
1) Is there a way that my Python program can read variables from the C program when the later finish its run?
2) Is there a more intelligent way to call the C program from python? The method I use above is just make a call to the OS. It seems to me a dumb way to do it. Is there a way I can call maybe the main() function of my C program from inside python or something like that?
-
Thanks for helping.