Calling cpp from python/SWIG

F

Frank

Hi,

I have the following problem:

I want to call a cpp program from python. Let's call this cpp program
fct. The problem is that I will parse a large array, say M1, to fct
and also receive a large array, say M2 back (each about 1000 x 1000).

Normally, I would write M1 to a file, call fct via
subprocess.Popen
write M2 in a file within fct, and read M2 with python.

I followed some threads discussing the use of swig in this context.

My questions are:

- is SWIG the best solution for my problem
- are there other ways besides SWIG
- can I find somewhere examples how to do that exactly

Thanks to all!

Frank
 
D

Dennis Lee Bieber

I want to call a cpp program from python. Let's call this cpp program

Confusing terminology... To most people, "program" means something
that can be run from a command line. In the case of C++, that would mean
a compiled & linked /executable binary file/.
fct. The problem is that I will parse a large array, say M1, to fct
and also receive a large array, say M2 back (each about 1000 x 1000).

Normally, I would write M1 to a file, call fct via
subprocess.Popen
write M2 in a file within fct, and read M2 with python.

I followed some threads discussing the use of swig in this context.

My questions are:

- is SWIG the best solution for my problem
- are there other ways besides SWIG
- can I find somewhere examples how to do that exactly

This sounds more like you want to call a function that exists in a
(binary link) library compiled from a C++ source file.

If "fct" IS a stand-alone "program", you're essentially limited to
variations of subprocess, os.system, etc.

SWIG allows one to "extend" Python with compiled library code, not
with stand-alone programs (to the best of my knowledge).

--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 

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,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top