publishing an already instantiated class

J jstier at cs.uvic.ca
Thu Jul 7 19:03:56 EDT 2005


Hi everyone,

Thanks for your awsome replies. I started replacing Javascript
with python 2 days ago and I already have my first scripts running.
Mainly due to the wealth of information in this blog.

I have a C++ object that is already instantiated and now
I want to give python a reference to it... Basically I have

class X
{
        typedef struct
        {
            PyObject_HEAD
            ScnNode* mObject;
        } PyStruct;

        static PyTypeObject PyType;

        static init()
        {
           PyType_Ready(&PyType) < 0)
           Py_INCREF(&PyType);
           PyModule_AddObject(sModule, "Node", (PyObject*) &PyType);
        }
};

I think that in the constructor of X I now have to make some calls in
order to provide access to this instance from a python script.... I
also think that I only want to get PyObject_New to be called, but not
PyObject_Init, because there I create a new instance of X when it is
instantiated through a script.... Am I on the right track here ?

Cheers
Jochen




More information about the Python-list mailing list