embedding python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tom fogal

    embedding python

    Hi all, I can't seem to find out how to get a python script to run from
    a C (well, C++...) program.

    In particular, I'm confused about how the execution of the example code
    at http://docs.python.org/ext/pure-embedding.html works. If I call the
    example code 'multiply.py' and I generate an executable named 'call' (as
    the page suggests), I had expected the following to work:

    ../call multiply.py multiply 3 2

    where 'multiply' is a function in multiply.py. The above comes back with
    an ImportError saying that there is "No module named multiply.py", and
    a similar message if I change 'multiply.py' to 'multiply' (again as the
    page would suggest).

    I saw somewhere (sorry, I forget where now) some code that would suggest
    that I need to tag my python files with a module name, and got the
    vague impression that something like:

    modname="multip ly"
    mod = __import__(modn ame)

    would do the trick. This doesn't seem to affect things though...

    Could anyone show me in the right direction towards just getting a
    simple 'hello world' type example to be run from a PyImport_<somet hing>
    call? I'm hoping I could figure it out without bothering anyone else
    from then on.

    Thank you,

    -tom
  • vincent wehren

    #2
    Re: embedding python

    tom fogal wrote:[color=blue]
    > Hi all, I can't seem to find out how to get a python script to run from
    > a C (well, C++...) program.
    >
    > In particular, I'm confused about how the execution of the example code
    > at http://docs.python.org/ext/pure-embedding.html works. If I call the
    > example code 'multiply.py' and I generate an executable named 'call' (as
    > the page suggests), I had expected the following to work:
    >
    > ./call multiply.py multiply 3 2[/color]

    How about "call multiply multiply 3 2" (notice the missing extension .py) ;)


    --
    Vincent Wehren


    [color=blue]
    >
    > where 'multiply' is a function in multiply.py. The above comes back with
    > an ImportError saying that there is "No module named multiply.py", and
    > a similar message if I change 'multiply.py' to 'multiply' (again as the
    > page would suggest).
    >
    > I saw somewhere (sorry, I forget where now) some code that would suggest
    > that I need to tag my python files with a module name, and got the
    > vague impression that something like:
    >
    > modname="multip ly"
    > mod = __import__(modn ame)
    >
    > would do the trick. This doesn't seem to affect things though...
    >
    > Could anyone show me in the right direction towards just getting a
    > simple 'hello world' type example to be run from a PyImport_<somet hing>
    > call? I'm hoping I could figure it out without bothering anyone else
    > from then on.
    >
    > Thank you,
    >
    > -tom[/color]

    Comment

    Working...