Python wrapper for C++ core

Jason tenax.raccoon at
Wed Oct 18 01:30:34 CEST 2006

holly.woodl... at wrote:
> Hi All
> Apologies in advance for the pretty basic question - but I can't seem
> to find an answer anywhere else.
> I am developing a fluid sim in C++ and have heard that many people use
> Python in conjunction with C++ for this sort of thing (especially in
> games dev).
> What I can't understand why you would want to do this. Obviously the
> core would be written in C++ (for my purposes anyway) so what parts
> would be written in Python? What is the benefit, in this situation, of
> using Python instead of C++?
> thanks for your help
> Holly

What would be the advantages?  Let's see if I can knock it down for

You didn't give any information about your fluid simulation other than
you are developing it in C++.  Whether or not you'd want to expose your
fluid sim objects to Python depends on your purposes.  If you code the
main fluid engine in C++ and expose it in Python, you might be able to:

  1) Easily run your fluid simulation over a variety of parameters.
Vary the equation constants so you can see how the simulation works
with water, rubbing alcohol, air, and molasses.

  2) Perform statistical analysis of your results.  Use one of the
various statistical packages to examine the results.  Use the CSV
module to save out an Excel-compatible set of results, or use the Win32
modules to start up Excel and populate a spreadsheet.

  3) Use Python to set up the specific physical layout for the fluid
simulation.  For a 2D fluid simulation, you might want to set up a
specific set of walls.  You can do that automatically, or use your own
custom file format and let Python deal with parsing it.

  4) Use Python to load models from different file formats into the
simulation.  For 3D fluid simulations, you'd most likely use CAD
generated models.  Create a basic C++/Python class for models that can
load triangles into the simulation.  For each format that you support,
use or write a Python class, derived from the basic model class, that
can parse that format and put the triangles into the model using the
superclass.  If the file format is text-based, Python's excellent
string manipulation can help out here.

  5)  Use Python to allow the user to "react" to certain conditions and
events during the simulation.  Perhaps the model changes in one
simulation at a given time (as a valve opens or closes).  Perhaps if
the model reaches a stable equilibrium, you'd like to end the
simulation so you don't need to know exactly when to end the

  6) Give your users the ability to perform any of the above.

What Python can give you is flexibility.  Whether or not this is useful
for you depends entirely on the goals of your program, and the design
of your program.  I'm sure there are other things Python can do for
you, but you'll need to figure them out (or post more information about
your program).


More information about the Python-list mailing list