Import / export values to/from C program

S

Steffen Jahn

Hi,

I stumbled across Python when trying to invoke *scripts* from C programs. The
idea is to set up some variables in the C program, export them, run a Python
script, and, after completion, import some variables back into the C program.
This way, I can keep the C program very flexible for certain types of changes.

Unfortunately, I can't see an API to export/import an PyObject directly.
I see currently only an indirect way: Implement import and export functions
in C which have to be called in the Python script (import function at
beginning and export function at end). Though I would prefer a *direct* access.

At the moment, I start thinking whether direct access is really better since
the script needs anyways to *know* of the variables which are available (makes
not much difference whether variable or function...)

Anyways, maybe somebody can tell me if such direct access is possible. A kick
in the right direction would be highly appreciated.

Thx, Steffen
 
R

Rick Ratzel

Steffen said:
Hi,

I stumbled across Python when trying to invoke *scripts* from C programs. The
idea is to set up some variables in the C program, export them, run a Python
script, and, after completion, import some variables back into the C program.
This way, I can keep the C program very flexible for certain types of changes.

Unfortunately, I can't see an API to export/import an PyObject directly.
I see currently only an indirect way: Implement import and export functions
in C which have to be called in the Python script (import function at
beginning and export function at end). Though I would prefer a *direct* access.

At the moment, I start thinking whether direct access is really better since
the script needs anyways to *know* of the variables which are available (makes
not much difference whether variable or function...)

Anyways, maybe somebody can tell me if such direct access is possible. A kick
in the right direction would be highly appreciated.

Not sure if this will help, but Elmer lets you run your Python code
from C, where you can pass values back and forth between the languages
without having to know the Python/C API. You do have to define an Elmer
interface file for your Python module though, but its pretty easy.
There are some examples on the website:

http://elmer.sourceforge.net

You did touch upon one of the main motivations for writing Elmer,
and that is to keep the calling C/C++ program flexible for changes and
prototyping new functionality...which is something Python is ideal for.
Since Elmer generates an interface that looks "native" to C, you can
easily replace the underlying Python code with C/C++ once you are
through prototyping...if you think it's necessary.
 
S

Simon Burton

Hi,

I stumbled across Python when trying to invoke *scripts* from C programs.
The idea is to set up some variables in the C program, export them, run a
Python script, and, after completion, import some variables back into the
C program. This way, I can keep the C program very flexible for certain
types of changes.

Check out Pyrex. It can probably do what you want (whatever that is - i'm
not quite sure.)

Simon.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top