[Tutor] Python to C++

Dinesh B Vadhia dineshbvadhia at hotmail.com
Fri Mar 21 23:37:17 CET 2008


Thank-you for all the suggestions for converting to C/C++ which will be followed up.  

Can we interface Python to a C++ library and if so how?

Dinesh

................................................................................
Date: Thu, 20 Mar 2008 17:21:52 -0000
From: "Alan Gauld" <alan.gauld at btinternet.com>
Subject: Re: [Tutor] Python to C++
To: tutor at python.org
Message-ID: <fru6bt$qg6$1 at ger.gmane.org>
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
reply-type=original

"Dinesh B Vadhia" <dineshbvadhia at hotmail.com> wrote

> Say because of performance, you might want to re-write/convert 
> Python code to C++.  What is the best way (or best practice) 
> to do this wrt the tools available?

It may be obvious but its worth noting that optimised Python may 
be faster than a badly written C port. So first make sure you have 
squeezed the best performance out of Python.

Secondly only rewrite the bits that need it so use the profiler to 
identify the bottlenecks in your Python code and move those 
to a separate module to reduce conversion effort.

After that the advice already given re pyrex/psycho etc is all good.

You might also find SWIG a useful alternative if you decide 
to rewrite the slow functions by hand. SWIG will help wrap 
those functions so that the remaining Python code can 
access them.

Alan G.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080321/96bf0732/attachment.htm 


More information about the Tutor mailing list