embedding python

T

tom fogal

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="multiply"
mod = __import__(modname)

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_<something>
call? I'm hoping I could figure it out without bothering anyone else
from then on.

Thank you,

-tom
 
V

vincent wehren

tom said:
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

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

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,206
Messages
2,571,069
Members
47,675
Latest member
RollandKna

Latest Threads

Top