embedding python

vincent wehren vincent at visualtrans.de
Wed Sep 15 00:53:04 EDT 2004


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



More information about the Python-list mailing list