1

Before simply answering "use SWIG" or "just write it to a file on disk" read this:

I have a C++ client/server program. The client requests data from the server.

The server generates data and calls various routines to check the data. If all the data is correct, it sends the data via socket to the client.

What I'd like to do is take this raw data (say it was a String type data) and replace my "various routines" with python programs.

To do this, the raw data will be passed to the python programs to be parsed and checked, then they will need to return a pass/fail value to the C++ server.

Any ideas?

1 Answer 1

1

That's quite backwards from the normal way of doing things, isn't it!

You have two main options:

  1. Keep the Python scripts as they are, run them using fork()/exec() or whatever is appropriate to your platform, and parse their output in C++;
  2. Use CPython's well-documented API to embed it in your C++ program, and invoke the scripts that way.
Sign up to request clarification or add additional context in comments.

3 Comments

Looks like #2 is going to be best for me. Thanks!
I don't know about that "well-documented". If find myself going to the actual Python sources to find out what is required, or what a "documented" function actually does. And of course, the simplest option would probably to do everything in Python.
Similarly, I could do everything in C++. I like the idea of having a core C++ and allowing Python "plug-ins"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.