Lost Password?

Go Back   CodeCall Programming Forum > Software Development > Python

Python Discussion forum for Python, a high-level language with simple syntax, but yet powerful.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-04-2008, 10:42 AM
BlueDream BlueDream is offline
Newbie
 
Join Date: May 2008
Posts: 4
Rep Power: 0
BlueDream is on a distinguished road
Default embedding python in C

Hi all, I'm tackling my very first python problem so I'm a bit of a newbie to python...

What I've got is a C program that is demonstrating inter process communication - by the use of pipes.

I've got a process that forks, with the child process generating a random number that then pipes the random number to the parent process.
Now what I want to do is use that variable within that process with python to print it to the command line (stdout/screen)

The difficulty I'm having is getting my C variable into the python program.... my code looks like this:


else if ( pid > 0 ) //if this is true this is the parent process
{
// close the file descriptor to set up child for reading
close (fd[1]);

//read the file descriptor and store the variable in pipeResult
read ( fd[0], &pipeResult, sizeof(float) );

//print the variable (just so I can see it piped correctly)
printf ("Read the value of pipe: %f\n", pipeResult);

//Initialise the python environment
Py_Initialize();

//Try to print the C variable in python.... This is not working
PyRun_SimpleString("print pipeResult");

// Close the python environment.
Py_Finalize();

} //end else - parent process

So it looks like I need to figure a way to get my 'C' variable into PyRun_SimpleString( )

Or I have been starting to wonder if it is possible to get the python program to read from one end of the pipe and for my 'C' program to send it down the other end.... This would eliminate the need for me to somehow get my 'C' variable into the python program, obviously introducing other complications such as getting the two different languages to communicate across the processes with a pipe....

Anyone have any ideas?

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to learn Python. Sir_Rimo Python 21 08-22-2008 08:16 AM
Python for developing software Kasper Python 8 08-06-2008 11:11 PM
Using python in C BlueDream C and C++ 2 05-04-2008 09:02 AM
Splitting Strings with Empty Separator (Python) Matt Python 3 05-18-2007 12:27 PM
Python Collection reachpradeep Python 1 03-03-2007 02:50 PM


All times are GMT -5. The time now is 12:06 AM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
LogicKills ........ 20.00000
sam ........ 20.00000
gaylo565 ........ 18.00000
|pH| ........ 15.00000
WingedPanther ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 67%

Ads