473,702 Members | 2,450 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python wrapper for C++ core

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

Oct 17 '06 #1
7 1571
holly.woodl...@ gmail.com 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.

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
simulation.

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).

--Jason

Oct 17 '06 #2
At 17 Oct 2006 16:05:40 -0700 ho************@ gmail.com 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
If they were using Python/Tk to develop a GUI, it makes sense (although
I would use Tcl/Tk, being a Tcl fan). In either case, SWIG can generate
the interface between C/C++ and Python/Tcl.
>
Holly

--
Robert Heller -- 978-544-6933
Deepwoods Software -- Linux Installation and Administration
http://www.deepsoft.com/ -- Web Hosting, with CGI and Database
he****@deepsoft .com -- Contract Programming: C/C++, Tcl/Tk

Oct 17 '06 #3
IMHO,

What I learned with the time and of course with books =) :

Python gives you rapid turnaround. You can try different approaches and
archictetures to solve the problem in much faster way than you would
with C++.

When you really need to crunch numbers, and numpy/othermodule is not
enough for you, then you would need to go down and optimize it in c++.

So, the ability to change, re-create and try another strategy would be
a killer reason for me to use python (like I have in the past) for
games or sim apps.

[]s
Robert Heller wrote:
At 17 Oct 2006 16:05:40 -0700 ho************@ gmail.com 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

If they were using Python/Tk to develop a GUI, it makes sense (although
I would use Tcl/Tk, being a Tcl fan). In either case, SWIG can generate
the interface between C/C++ and Python/Tcl.

Holly

--
Robert Heller -- 978-544-6933
Deepwoods Software -- Linux Installation and Administration
http://www.deepsoft.com/ -- Web Hosting, with CGI and Database
he****@deepsoft .com -- Contract Programming: C/C++, Tcl/Tk
Oct 18 '06 #4
At 17 Oct 2006 17:19:03 -0700 "handful of nothing" <ha*****@gmail. comwrote:
>
IMHO,

What I learned with the time and of course with books =) :

Python gives you rapid turnaround. You can try different approaches and
archictetures to solve the problem in much faster way than you would
with C++.
Yes, this is especially true of GUI programming. I can create a Tcl/Tk,
*cross platform* GUI front end very rapidly and that GUI can be easily
and quickly 'tweaked' as needed, again very rapidly. I guess a Python
program could build and tweak a Python/Tk GUI as quickly.
>
When you really need to crunch numbers, and numpy/othermodule is not
enough for you, then you would need to go down and optimize it in c++.

So, the ability to change, re-create and try another strategy would be
a killer reason for me to use python (like I have in the past) for
games or sim apps.

[]s
Robert Heller wrote:
At 17 Oct 2006 16:05:40 -0700 ho************@ gmail.com 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
If they were using Python/Tk to develop a GUI, it makes sense (although
I would use Tcl/Tk, being a Tcl fan). In either case, SWIG can generate
the interface between C/C++ and Python/Tcl.
>
Holly
>
>
--
Robert Heller -- 978-544-6933
Deepwoods Software -- Linux Installation and Administration
http://www.deepsoft.com/ -- Web Hosting, with CGI and Database
he****@deepsoft .com -- Contract Programming: C/C++, Tcl/Tk

--
Robert Heller -- 978-544-6933
Deepwoods Software -- Linux Installation and Administration
http://www.deepsoft.com/ -- Web Hosting, with CGI and Database
he****@deepsoft .com -- Contract Programming: C/C++, Tcl/Tk

Oct 18 '06 #5
ho************@ gmail.com 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++?
I see "fluid sim" and "games dev" in the same post, which kind of makes
me scratch my head. What would you need fluid sim for in a game?
Maybe it's a flight sim; I suppose now computers are fast enough to
attempt a low-fidelity CFD (computational fluid dynamics) in real time.
(Or maybe you mean something different by fluid sim, like a puzzle
game involving valves or something.)

Anyways, combining Python with C is useful for all kinds of
applications, not just games and simulations, because Python has
different strengths than C. C is faster and can inteface easily with
hardware and the OS; Python is better at pretty much everything else.
It takes care of a lot of stuff you'd have to do yourself in C.

Speaking as someone who studied a lot of CFD in college, I think Python
in particularly is very useful for extreme numerical work. (If that's
not what you're talking about, never mind the rest of the post.)

The people who do fluid simulations are engineers (classical sense),
not programmers. These people do NOT like to program. They like to
fiddle with arrays and do arithmetic; stuff like memory management,
input/output, and other computer-science-ish tasks are a pain in the
neck. Time spent doing that kind of stuff is time not spent doing
useful things like hand-optimizing the hell out of the numerical code.

Python (even with Numeric) is simply too slow for high-end CFD
applications, so the numerical part is almost always written in C or
Fortran. But C and Fortran are terrible languages to do things like
memory management and I/O in. Python, OTOH, is terrific for these
things. It's a great language for people who don't like to program.
Comparable languages such as Ruby are also good for I/O and stuff, but
I think Python's the best of all for numerical work:

1. Large support community
2. Large standard library and lots of third-party packages out there,
addresses all kinds of needs
3. A very spiffy package, pyfort, to interface with Fortran, which can
also works for C functions that act like Fortran (which is often the
case in a numerical application). Relatively straightforward general
interface to C if pyfort won't do.
4. numpy, a very good, well-maintained package which allows Python
programs to operate on arrays directly (useful for tasks that don't
need to be hyper-optimized).
5. Superficially similar to C and Fortran, which is no small thing for
engineers
Carl

Oct 18 '06 #6

Thanks everyone for the responses - I think I have a better
understanding now. I can handle all the messy I/O in Python and use C
for the number crunching. I especially like the idea of using python to
output the results to excel.

OK time to learn Python i think - any tips on best place to start
(tutorials/documentation etc). I have a pretty comprehensive background
in C/C++/Java and a bit of experience some other scripting languages so
its really a matter of syntax/libraries rather than programming
theory/constructs
>see "fluid sim" and "games dev" in the same post, which kind of makes
me scratch my head. What would you need fluid sim for in a game?
sorry i was just listing places I had seem people waxing lyrical on the
benefits of python. I am not doing games development - I have just
heard lots of games developers saying they use python

Thanks again for all the help!

Holly

Oct 19 '06 #7
On 19 Oct 2006 03:10:55 -0700, Holly <ho************ @gmail.comwrote :
>
Thanks everyone for the responses - I think I have a better
understanding now. I can handle all the messy I/O in Python and use C
for the number crunching. I especially like the idea of using python to
output the results to excel.

OK time to learn Python i think - any tips on best place to start
(tutorials/documentation etc). I have a pretty comprehensive background
in C/C++/Java and a bit of experience some other scripting languages so
its really a matter of syntax/libraries rather than programming
theory/constructs
Be sure to check Boost.Python to create Python bindings for your project(s):
http://boost.org/libs/python/doc/tut...tml/index.html

--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
Oct 19 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2582
by: Vio | last post by:
Hi, I've been trying to embed (statically) wxPy alongside an embedded py interpreter on a linux/gtk box. At one point, for some reason misc.o linking reported "multiple definitions of wxGetFreeMemory()". Since wxGetFreeMemory() seemed effectively unused in gtk, I just commented it out in misc_wrap.cpp (didn't want to patch SWIG to regenerate the wrapper code, so hacked the generated cpp source), and replaced...
24
2509
by: huy | last post by:
Hi, Just wondering if there were any plans (or existing projects) similar to Java webstart for Python. I think this would be a boon for python. I would love to start my new project using Python but the deployment (and long term upgrading) factor is a major itch which pyfreeze and py2exe just doesn't scratch properly. Thanks
16
5208
by: PyDenis | last post by:
Today, I found strange error while using py2exe: 1. I wrote simple program and save as 1.py: import win32ui import win32con win32ui.MessageBox('Test messageBox.' , 'Test', win32con.MB_OK | win32con.MB_TOPMOST ) 2. I create 1_setup.py file for py2exe:
1
1851
by: Mark Harrison | last post by:
Right now I'm using Boost Python to wrap some C++ code so that applications from both languages can use it. This is great, but I'm rapidly coming to the conclusion that a lot of this work is better coded in Python. There's nothing particularly CPU-bound, and the comprehensive Python library is a big help. So, I'm looking for a C++ wrapper generator, so that I can write a class in Python, and then have a .h and .cpp generated
7
3676
by: kenneth.m.mcdonald | last post by:
Are then any currently active and reasonably mature Python plugins/ apis/whatever for programming/scripting OpenOffice? The page I've found is http://udk.openoffice.org/python/python-bridge.html, but it was last updated more than a year ago. Thanks, Ken
27
2921
by: bcwhite | last post by:
I've been trying to find out what the future of Python is with regard to Tk. It seems there are several interfaces that make use of new functionality, including "Tile" and "Ttk". If I want to write a program that will run under the standard Python distribution of the future, what extension module should I work with today? Thanks!
7
1351
by: digimotif | last post by:
All, I'm currently working with a small development company on a PHP application they already have. There are several processing tasks that could be scripted in Python and run in the background to modify a database, instead of the way they have it now, which waits for a webpage to return from processing. There is also the possibility of building client gui applications that work with the database as well, so I'm looking for a way I...
5
3394
by: Raja | last post by:
Hi, I am trying to develop a a GDB wrapper script in python which is able to extract a stack trace and all relevant data. Has anyone does this before ? Even some basic idea or code as to how to proceed would be great. Thanks, Raja.
0
8738
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9234
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8979
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7829
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5907
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4412
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3104
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2036
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.