[PyKDE] Using SIP to wrap python objects

Jim Bublitz jbublitz at nwinternet.com
Fri Jun 13 08:34:00 BST 2003


On Thursday June 12 2003 16:31, Rob Knapp wrote:
> I've found myself in a position where I need to present a
> python object to a C++ object, and it needs to look like a C++
> object.  The target application knows nothing of python.

> Would it be possible to create an object using SIP that I can
> inherit from and use the SIP api to convert into a CppPointer?

> Is there another/better way to achieve this?

Unless I'm misunderstanding (always a possibility), what you want 
to do is the reverse of what sip does. Sip binds C++ objects to 
Python (so that you can use C++ objects in a Python program), 
and you appear to want to communicate with a Python object from 
a C++ program.

The standard Python API has all of the C functions you need to 
accomplish this - see the Python/C API Manual that's included in 
the Python docs. You can find good examples on the web, or Lutz' 
"Programming Python" (O'Reilly) has some good example code and 
documentation (it's out of date, but the Python/C API stuff is 
still useful for the basics).

I didn't find it too difficult to use the standard Python API - 
it's likely to be easier learning that than learning sip 
(especially since sip itself is based on the Python API to some 
extent). I'd estimate a day or two for a good C/C++ programmer 
for the Python API and longer for sip. It may not be important 
in your application, but an added benefit is that you'll figure 
out pretty quickly how to embed the Python interpreter into your 
app, and can then use Python to script it or develop extensions.

Jim




More information about the PyQt mailing list