Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > import python module from C++ code

Reply
Thread Tools

import python module from C++ code

 
 
Arthur Mc Coy
Guest
Posts: n/a
 
      03-04-2011
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
 
Reply With Quote
 
 
 
 
Arthur Mc Coy
Guest
Posts: n/a
 
      03-04-2011
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
 
Reply With Quote
 
 
 
 
Arthur Mc Coy
Guest
Posts: n/a
 
      03-04-2011
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
 
Reply With Quote
 
Markus Schaber
Guest
Posts: n/a
 
      03-07-2011
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
imp.find_module don't found my module but standard import statement can import this module… why ? Stéphane Klein Python 0 07-05-2011 07:36 AM
Why 'import module' will not import module.py but the directorymodule? Peng Yu Python 0 10-31-2009 11:51 PM
Handling import conflicts when module has the same name as a library module that it needs to import? plb Python 0 02-08-2005 01:08 PM
Handling import conflicts when module has the same name as a library module that it needs to import? plb Python 0 02-08-2005 01:01 PM
import vs from module import : any performance issue? Pierre Rouleau Python 4 03-07-2004 05:06 PM



Advertisments