Reputation: 3709
in my C++
application, I want to invoke a Python
script to do some processing works. I have searched in Google and found there are two ways to do this:
(1). use the `system` command. Just like this, `system('python myscript.py');`
(2). use the `PyRun_SimpleString("execfile('myscript.py')");`
I want to ask that, which way is better and is there any better way to do this work?
Thanks.
Upvotes: 1
Views: 217
Reputation: 1
I want to ask that, which way is better and is there any better way to do this work?
You should notice that the python engine is written in C and therefore provides a native C-API. This allows you to interact more directly with python code, by means of calling functions and using python objects.
If you want to integrate it from C++ code without hassling with the C-API, there's the excellent and easy to use boost::python library.
Upvotes: 2
Reputation: 5231
I think that boost provides libraries to do that. But I never used them. http://www.boost.org/doc/libs/1_55_0/libs/python/doc/
Upvotes: 1