View Full Version : Python to C++
I am learning Python right now and it is pretty cool. Just out of curiosity, would it be a easy transition to learn C++ after I master Python?
mgb_phys
Feb12-09, 06:02 PM
Why would you want to!
Often people coming from a higher level language write better C++ code (using boost and STL) rather than people coming from C/Fortran who write at too low a level.
Boost and STL, never heard of them. I am new to programming:)
Well, I have noticed some really good computational software that requires C++, like open foam for CFD.
I would like to eventually get into these types of programs.
So boost allows me to interface python with c++ programs, is that correct?
So I would be able to use python for open foam?
mathmate
Feb15-09, 02:16 PM
If you do a lot of intense computations such as CFD, it does not hurt to start programming in C++ which gives you a lot more return for your CPU seconds.
Python and other high level languages make excellent prototyping tools.
mgb_phys
Feb15-09, 02:23 PM
If you have an existing CFD (or whatever) library it might be worth looking for a Python wrapper, or making some wrappers using boost::python.
Let C++ (or Fortran) do the heavy lifting an write your own program on top of this in Python - you get a lot better value for your programming hours and a reduction in all-night bug hunts.
shoehorn
Feb15-09, 05:14 PM
For what little it's worth, I've often found Boost::Python to be perhaps the most severely lacking component in the Boost libraries. (The reasons are technical and I won't discuss them here.)
On the other hand, Swig (http://www.swig.org/) is a great way of wrapping C/C++ code so that it can be used with Python (among many other languages). It's discussed in several places but a really useful introduction to it, as well as to the use of Python more generally in a scientific context, is Langtangen's Python Scripting for Computational Science (http://www.amazon.com/Python-Scripting-Computational-Science-Engineering/dp/3540739157/ref=sr_1_1?ie=UTF8&s=books&qid=1234739638&sr=1-1). (Langtangen's book is wonderful for many reasons but it also does a really good job of illustrating how Python can be used to interface with Fortran and C/C++ code, something that's essential knowledge if you're going to be working with scientific libraries.)
mgb_phys
Feb15-09, 05:33 PM
Thanks for the book pointer,
I've noticed a couple of projects switching back to SWIG. When I last used it I remember it generated a very 'c' like interface, I've only used boost:python for a few trial projects.
shoehorn
Feb15-09, 11:19 PM
Thanks for the book pointer,
I really can't recommend it highly enough. It takes a bit of effort, but there's an enormous amount of useful information in there, particularly regarding Numpy and wrapping Fortran or C/C++ code in Python. It's a gem of a book.
mheslep
Feb16-09, 04:10 PM
For what little it's worth, I've often found Boost::Python to be perhaps the most severely lacking component in the Boost libraries. (The reasons are technical and I won't discuss them here.)
On the other hand, Swig (http://www.swig.org/) is a great way of wrapping C/C++ code so that it can be used with Python (among many other languages). It's discussed in several places but a really useful introduction to it, as well as to the use of Python more generally in a scientific context, is Langtangen's Python Scripting for Computational Science (http://www.amazon.com/Python-Scripting-Computational-Science-Engineering/dp/3540739157/ref=sr_1_1?ie=UTF8&s=books&qid=1234739638&sr=1-1). (Langtangen's book is wonderful for many reasons but it also does a really good job of illustrating how Python can be used to interface with Fortran and C/C++ code, something that's essential knowledge if you're going to be working with scientific libraries.)I have Langtangen and agree it's excellent. I'd disagree w/ the recommendation of Swig now, especially for those starting out. Ctypes IMO has eclipsed it as the best bet: far easier to use, learn, and debug, comes builtin w/ Python, and for some things out performs Swig substantially. Downside is Ctypes won't handle C++
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.