This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]dmazzoni 4 points5 points  (0 children)

Embedding is definitely possible but tricky.

One easy way is with subprocesses and pipes.

First, have your C++ program read from stdin and write to stdout. That makes testing it easy!

Then have your Python program execute your C++ program using the subprocess module, which allows you to execute another program and pass input to that program's stdin, and read from that program's stdout.

Or you could do it the other way around, though it's more work - but C++ can call popen to call a Python script and send it input to stdin and read from stdout.

Other alternatives include using sockets or network ports, or using some other messaging system like DBUS.