embedded python questions

db dbunix at yahoo.com
Tue May 6 17:31:03 EDT 2003


Hi,

Please CC me as Im not subscribed.

Is it possible to pass variables from C into an
embedded Python interpreter and have them available
from inside a script that gets executed via something
similar to PyRun_SimpleFile()? For example, I want to
be able to accept a socket connection in C, pass it
into a python script, and have it available to the
script when it executes.

Eg. (in C)
Py_Initialize();
...
mysock = accept(connfd, (struct sockaddr *)&addr,
&size);
Py_PassVarToPython( "sock", (PyObject *)&mysock );
PyRun_SimpleFile( scriptfd, "test.py" );
...
Py_Finalize();

Then, from the test.py script be able to access the
socket via os.read(), os.write(), etc:

buff = os.read( sock, 1024 );
...
os.write( sock, "hello world" );

Im sure that the call to python is not acctually going
to be PyRun_SimpleFile(). That is just to illustrate
the functionality I want, i.e., handle some basics is
C, then turn the data over to the embedded interpreter
that executes an external script.

Thanks,

db

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com





More information about the Python-list mailing list