[PyKDE] Using SIP to call Python from C++

Niac Neb niacneb at yahoo.com
Thu May 19 15:26:50 BST 2005


James,

I'm assuming you don't have an example of calling
Python from C++.  Your previous post indicated you'd
done this numerous times.  The code snippet pretty
much left me hanging.

The folks at Riverbank indicated that SIP didn't even
facilitate this capability.

Perhaps more tutorials/WIKI will evolve as SIP becomes
mature.  I'll look forward to it.  For now, the
Boost.Python community seems more responsive to posts.
 I guess that's due to a larger user base.

Thanks anyways,
  Niac


--- James Emerton <ephelon at gmail.com> wrote:
> Here's the most maintainable way of calling Python
> from C++.  This
> method keeps your C++ out of your Python and your
> Python out of your
> C++.  As a bonus feature, if the Python
> implementation gets too slow,
> you can rewrite in C++ without needing to touch any
> client code.
> 
> //
> // iface.h
> struct IFoo {
>   virtual float wonk(float, float) = 0;
> };
> 
> //
> // iface.sip
> %Module foo
> class IFoo {
> %TypeHeaderCode
> #include "iface.h"
> %End
> 
> public:
>   virtual float wonk(float, float) = 0;
> };
> 
> //
> // impl.py
> from foo import IFoo
> 
> class FooImpl( IFoo ):
>     def wonk( self, n1, n2 ):
>         return n1 * n2
> 
> 
> The only thing left to do in instantiate FooImpl and
> hand it back to
> some C++ function.
> 
> James
> 


		
Yahoo! Mail
Stay connected, organized, and protected. Take the tour:
http://tour.mail.yahoo.com/mailtour.html




More information about the PyQt mailing list