| Store | Cart

Re: [C++-sig] How to get output from python embedded in VC++

From: Stefan Seefeld <ste...@seefeld.name>
Sat, 22 Jul 2017 13:01:29 -0400
On 21.07.2017 23:17, Jian wrote:
> Hi Imre,>> I tried to use boost.python as you advised. Build boost.python with >> But I got a error in the import.hpp as below:> ------------------------import.hpp start> ----------------------------------------> namespace boost > { > namespace python > {>> object BOOST_PYTHON_DECL import(str name)> {>   // should be 'char const *' but older python versions don't use> 'const' yet.>   char *n = python::extract<char *>(name);> *  python::handle<> module(PyImport_ImportModule(n));   <---here is> where the error raised. n is "__main__"*>   return python::object(module);> }>> }  // namespace boost::python> }  // namespace boost> ------------------------import.hpp> end---------------------------------------->> I copied your code and just replaced 'script.py' with the name of my> own file. I found the error raised when the code importing module> "__main__". >> That's my first time to use boost.python. Could you help about this issue?

This probably means you haven't initialized Python correctly. A good
starting point might be this example:
https://github.com/boostorg/python/blob/develop/example/quickstart/embedding.cpp

(I'm the Boost.Python maintainer. While I'd be happy to help you using
Boost.Python, I think this is mostly orthogonal to your original
question about how to capture output generated by you embedded Python.)



Best,
        Stefan




-- 

      ...ich hab' noch einen Koffer in Berlin...

_______________________________________________
Cplusplus-sig mailing list
Cplu...@python.org
https://mail.python.org/mailman/listinfo/cplusplus-sig

Recent Messages in this Thread
Jian Jul 20, 2017 03:25 am
Stefan Seefeld Jul 20, 2017 02:34 pm
Jian Jul 21, 2017 02:03 pm
Stefan Seefeld Jul 21, 2017 02:15 pm
Horváth Imre István Jul 20, 2017 07:22 pm
Jian Jul 21, 2017 02:28 pm
Horváth Imre István Jul 21, 2017 03:13 pm
Jian Jul 22, 2017 03:17 am
Stefan Seefeld Jul 22, 2017 05:01 pm
Jian Jul 23, 2017 07:15 am
Stefan Seefeld Jul 23, 2017 03:06 pm
Jian Aug 01, 2017 02:33 am
Messages in this thread