Motivation¶
Python can be readily connected with other languages.This way, existing libraries in other languages can be used.
Programming in Python is rather comfortable and efficient.The speed of Python programs for some tasks is considerablyslower than for programs in other languages such as C/C++, C#,Java, or FORTRAN.As a solution slow program parts can be reimplemented inother languages and seamlessly incorporated in Python.
Furthermore, Python is often termed “glue languages” becauseof its ability to connected very different systems. The connectionof libraries and programs that are implemented in other languagesplays a important role for this ability.
Course Content¶
Introduction to Example¶
We use a computationally intensive example throughout the course.This allows for comparison of the different extension methods.
Use of Python’s C-API¶
Standard Python is implemented in C and offers a comprehensiveAPI for writing extensions.The basics of this API are taught. A working extension willbe developed by hand that can be used by a Python program.
Python Extensions with Pyrex/Cython¶
Pyrex is a special language for writing Python extensions.It has mainly Python syntax with some limitations and some additionsthat allow for automatic translation into C code suitableto be compiled in an Python extension.Examples are used to show how Pyrex works. The possibilities ofincorporating existing C programs are also explained.
Use of DLLs with ctypes¶
The package ctypes allows to access DLLs or shared libraries from Python.It works on the operating systems Windows, Windows CE, Mac OS X, Linux,Solaris, FreeBSD, and OpenBSD. The language in which the DLL is implementeddoesn’t matter.The usage of ctypes is introduced with examples. Under Windows Microsoft’s.NET compiler und the mingw (gcc) compiler are used to compile the DLL.The shared library under Linux Linux is compiled with the gcc.One focus is type conversion between Python and the DLL.
Automatic generation of Extensions with SWIG¶
The “Simplified Wrapper and Interface Generator” (SWIG) allowsto make C/C++ libraries accessible from 13 different languages.One of them is Python. The way SWIG works is covered usingexamples in C as well as in C++.
Jython¶
Jython is an implementation of Python in Java. It allows to accessJava classes directly.The course covers the basics of Jython programs. Examplesfor use of existing Java classes as well as self written classesare used.
IronPython¶
IronPython is a implementation of Python in .NET. It allowsAccess to all .NET features and makes it a first class .NETlanguage right next to C# and Visual Basic.The course introduces IronPython, demonstrates how to use.NET assemblies, and how access self written C# classes.
Use of FORTRAN Subroutines from Python¶
FORTRAN is one of the oldest programming languages but itis still in heavy use for scientific applications dueto its high performance.There are many old but well proven numerical librariesthat can be used from Python.
The usage of F2PY to connect FORTRAN77 as well as FORTRAN90/95programs with Python is demonstrated. One focus are object-orientedinterfaces to those libraries.
Exercises¶
The participants can follow all steps directly on their computers.There are exercises at the end of each unit providing ampleopportunity to apply the freshly learned knowledge.
Course Material¶
Every participant receives comprehensive materials in PDF formatthat cover the whole course contentas well as all source code.
Recommended Module Combinations¶
The module Optimizing Python Programs covers supplementary topics.The course Python for Scientists and Engineers might also be of interest.
The course may be combined with the coursePython for Non-Programmersor Python for Programmers.