[C++-sig] Re: Creating an instance of a Python class in C++: PyRun_String?
dirk at gerrits.homeip.net
Fri Nov 15 08:53:58 CET 2002
David Abrahams wrote:
> Dirk Gerrits 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
> >Upon further RTFMing on start tokens, I tried this:
> >// Create and use an instance of the Python derived class
> >Base* py = python::extract(
> > PyRun_String("PythonDerived()\n", Py_eval_input, 0, 0));
> >This gives an access violation in find_instance_impl which is called
> >by extract_pointer::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?
I looked at that one, as I said in my initial post. However the example
creates a new python::object instance of a wrapped C++ class. Not of a
Python class. Is there some way to create a class_ object from a Python
class that I'm not aware of?
I don't really see how the example would compile BTW, because value is
declared a non-const member function and it is called through the const
More information about the Cplusplus-sig