473,325 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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="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
1 1556
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Robey Holderith | last post by:
Anyone know a good way to embed python within python? Now before you tell me that's silly, let me explain what I'd like to do. I'd like to allow user-defined scriptable objects. I'd like to...
4
by: Alicia Haumann | last post by:
I accidentally sent this to webmaster@python.org, so this could be a duplicate if "webmaster" forwards it to this list. :{ Hi, there. Thanks for any help that can be offered. I've been...
0
by: adsheehan | last post by:
Hi, I am embedding Python into a multi-threaded C++ application runnig on Solaris and need urgent clarification on the embedding architecture and its correct usage (as I am experience weird...
1
by: amit | last post by:
Hello, I am currently studying how to embedd python. I am developing a graphical C++ application. My goal is to embedd python script that will control some kind of animation. I have some...
1
by: Tommy Nordgren | last post by:
I want to write an application that embeds and extends (at least) the Python and Perl interpreters. Now i want to find as much as possible about the Python tools used for extending and embedding...
4
by: adsheehan | last post by:
Hi, I am embedding Python into a multi-threaded C++ application running on Solaris and need urgent clarification on the embedding architecture and its correct usage (as I am experience weird...
8
by: Thomas Bartkus | last post by:
Name: lib64python2.4-devel Summary: The libraries and header files needed for Python development Description: The Python programming language's interpreter can be extended with dynamically...
1
by: Kakacek | last post by:
Hello All, Let's say I have a following python code: class hw_class: def __init__(self): pass def hello_world(self): print 'Hello World!' create_instance('hw_class', 'hw')
2
by: John Dean | last post by:
Hi Could somebody, please tell me where I can find information about embedding Python into a C/C++ application. The example in the docs is rather simple. I am looking for something a bit more...
0
by: Severian | last post by:
I am working on embedding Python 2.5 in my C++ application, and I have a few questions: 1) My application is multi-threaded; what problems should I be aware of if I create a separate interpreter...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.