Converting Python app to C++ completely

Ken Seehof kseehof at
Tue Sep 3 23:54:43 CEST 2002

> Hi all,
... snip ...
> Now, what I want to do is write the thing in C++. The reason? heh,
> because I want to ;) Well, actually I want to learn C++ too, and I would
> like to have the performance of a compiled program for larger data sets
> (just for fun and comparison more than anything).

Hmm.  I guess that could be a good reason.  In practice, the only real
reason to do a complete python to C++ conversion that I have ever seen
is to reduce the applications footprint size (i.e. exclude the python
libraries).  Speed is not a good reason to convert the entire application.
You can get all the speed you need by converting individual components to
C++ as extensions.

I recommend that you learn how to write extensions, or better yet, learn
how to use Boost.Python:

I'd doubt that converting the GUI code from wxPython to wxWindows would
make much difference.  Has anyone done wxPython vs wxWindows benchmark
comparisons?  In most cases changes in GUI response time will be irrelivant,
except maybe high frequency events such as mouse move handling when you
want smoothness.

> 1) How easy is it to convert existing Python code to C++? I read that
> each line of C++ code is roughly equivilent to 5-8 lines of C++ code,
> but is the conversion a simple task or is it troublesome?

Actually, you can convert your entire python program into 1 line of C++
code :-)

> 2) Are there any pitfalls to beware of - I understand that dealing with
> memory and pointers might be a problem, but like I said earlier, I just
> don't really know?

Yes, I think your biggest issue will be memory management.

> 3) Does C++ have equivilent functional constructs like reduce and map?
> These helped to make my code much cleaner, tighter and faster, and I
> would miss them dearly.

Don't bother.  Just use for loops in C++.

> btw - the code I am writing doesn't rely upon any platform specific
> stuff at all and is quite portable in Python - I will be aiming for the
> same thing in Python and assume it will be possible.

C++ and wxWindows are almost as portable as Python and wxPython.  C++
varies a bit:

More information about the Python-list mailing list