Thursday 11:30 AM–12:10 PM in Room 2

Python, C, C++, and Fortran Relationship Status: It’s Not That Complicated

Philip Semanchuk

Audience level:
Intermediate

Description

One of Python’s strengths is that it can use code written in compiled languages like C, Fortran and C++.

This talk gives an overview of your many options for getting Python to call and exchange data with code written in a compiled language. The goal is to make attendees aware of choices they may not know they have, and when to prefer one over another.

Abstract

It’s commonly advised to write all of one’s code in Python, and then fix performance bottlenecks with a compiled language like C. But how does one get Python and C talking?

Suppose you’d like to use Python more often, but you have 20 years of homegrown Fortran libraries and you don’t want to abandon that investment. Can Python use your Fortran libraries? What if your code has to be written in C in order to talk to a scientific instrument, but you’d rather work in Python. Can you get Python to talk to your hardware driver? Can you have your cake and eat it too?

The answers are yes, yes, and yes. This talk will give you an overview of your many options for getting Python to call and exchange data with code written in a compiled language.

This will include popular choices like the ctypes standard library module, Cython, and writing an extension in C, as well as some less obvious choices like SWIG, embedding Python, and Boost.Python. I’ll discuss some of the pros and cons of each technique and suggest scenarios which play to their respective strengths.

The goal of this talk is to make attendees aware of choices they may not know they have, and when to prefer one over another.