import python module from C++ code

A

Arthur Mc Coy

Hi all,


I have a C++ application. I have a .cpp file which is not a main
program, but a class where I want to call python script
(doSomething.py file).

I'm using embed python like in a tutorial here:
http://www.codeproject.com/KB/cpp/embedpython_1.aspx

But the tutorial is bad. It does not explain howto create python
module which they call in their example. doSomething.py file contains
two classes, one of them I use externally (its functions).

So I need to PyImport_Import(py_module) by name of this py file, but
when I try to do that it fails. Please, give me some examples.


If needed, I can attach my code as well.
Thank you, waiting for anybody's response!
Be happy.

Arthur
 
A

Arthur Mc Coy

The problem is "how to write python module under SWIG for C++
application"

Nor SWIG documentation neither embeding python documentation does not
answer to this.


If you can help, please, share your idea.

Arthur
 
A

Arthur Mc Coy

Still need the answer to the question: " howto embed given python file
(which contains python class and its members) into the c++
application ? "

I have to pass the arguments from c++ to python and back so I need to
do conversions. They are ok. Fails PyImport_Import(my_module) call
saying "No module called mymodule". Then I need to create a mymodule
based on given python file (its name mymodule.py). Can it be achieved
using SWIG ?

I'm very curious and looking for some feedback if possible :)
Be happy.

Arthur
 
M

Markus Schaber

Hi,
von Arthur Mc Coy:
Still need the answer to the question: " howto embed given python file
(which contains python class and its members) into the c++ application
? "

There is no straight way of embedding a Python module into a c++
application.

You will have to embed the python interpreter, and command it to load
the module in question and execute the code you want.
I have to pass the arguments from c++ to python and back so I need to do
conversions. They are ok. Fails PyImport_Import(my_module) call saying "No
module called mymodule". Then I need to create a mymodule based on given
python file (its name mymodule.py). Can it be achieved using SWIG ?

Did you configure the module search path properly?

Regards,
Markus
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top