By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,363 Members | 1,731 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,363 IT Pros & Developers. It's quick & easy.

embedding python

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
tom fogal wrote:
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) ;)
--
Vincent Wehren

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

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.