Metaprogramming in Python


Metaprogramming is the process of writing code which manipulates existing code, such as functions or classes. It is a simple technique which can eliminate code repetition without introducing inheritance classes or multiple similar functions.

The Workshop

The workshop will be taught by Lucy Upton, a first year PhD student from the Next Generation Computational Modelling (NGCM) CDT. It will be taught through iPython notebook, and will consist of a short talk, live-demonstrations and exercises in Python.

The aim of this workshop is to introduce the concept of metaprogramming and to explain why and when to use it. You will learn to write and implement wrappers and decorators for both function and classes. By the end of the session, you should be confident to go forth and use metaprogramming in your code.


This workshop will require familiarity with programming in Python.

All are welcome, please bring a laptop with either Python and Jupyter or VirtualBox installed to be able to take part in the exercises.

Install Python and Jupyter

Comprehensive instructions can be found at:

or Download the Virtual Machine

If you do not wish to download Python and Jupyter, but you have VirtualBox or can download VirtualBox, please download the virtual machine for this session. This can be found at:

The documents used in this session can be found at