Import / export values to/from C program

Discussion in 'Python' started by Steffen Jahn, Apr 13, 2004.

  1. Steffen Jahn

    Steffen Jahn Guest

    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
    Steffen Jahn, Apr 13, 2004
    #1
    1. Advertising

  2. Steffen Jahn

    Rick Ratzel Guest

    Steffen Jahn wrote:
    > 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.
    Rick Ratzel, Apr 13, 2004
    #2
    1. Advertising

  3. Steffen Jahn

    Simon Burton Guest

    On Tue, 13 Apr 2004 13:47:51 -0700, Steffen Jahn wrote:

    > 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.
    Simon Burton, Apr 14, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGF2aWQgVmFsbGU=?=

    Invalid export DLL or export format

    =?Utf-8?B?RGF2aWQgVmFsbGU=?=, Oct 29, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    3,598
    =?Utf-8?B?RGF2aWQgVmFsbGU=?=
    Oct 29, 2003
  2. =?Utf-8?B?U2l1?=

    Export and Import from Excel into a Web page

    =?Utf-8?B?U2l1?=, Feb 28, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    13,821
  3. saket
    Replies:
    0
    Views:
    460
    saket
    Jan 4, 2006
  4. Robert Mazur

    Eclipse Export and Import

    Robert Mazur, Jun 7, 2004, in forum: Java
    Replies:
    2
    Views:
    11,775
    Dale King
    Apr 15, 2006
  5. Maarten Porters
    Replies:
    1
    Views:
    414
    Florian Gilcher
    Jul 28, 2008
Loading...

Share This Page