[C++-sig] Re: Creating an instance of a Python class in C++: PyRun_String?

David Abrahams dave at boost-consulting.com
Fri Nov 15 01:07:01 CET 2002


Dirk Gerrits <dirk at gerrits.homeip.net> writes:

> Dirk Gerrits wrote:
>
>> Firstly, I don't know which arguments to feed into PyRun_String. The
>> python.org docs didn't really help me that much: I don't have any
>> dictionaries of globals and locals, and what exactly is a start
>> token?
>
> Upon further RTFMing on start tokens, I tried this:
>
> // Create and use an instance of the Python derived class
> Base* py = python::extract<Base*>(
>      PyRun_String("PythonDerived()\n", Py_eval_input, 0, 0));
> py->f();
>
> This gives an access violation in find_instance_impl which is called
> by extract_pointer<Ptr>::extract_pointer(PyObject* obj) as far as I
> can tell. And the Base& version wouldn't compile as I said.
>
> What (else) am I doing wrong?

Does

   http://www.boost.org/libs/python/doc/v2/extract.html#examples

help?


-- 
                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution





More information about the Cplusplus-sig mailing list