View on GitHub


Material for the course "Python best practices", Scientific Software Center, Heidelberg University

Code style: black


Material for the course “Python best practices”, Scientific Software Center, Heidelberg University

Inga Ulusoy, October 2022

Python has rapidly advanced to the most popular programming language in science and research. From data analysis to simulation and preparation of publications, all can be done in Python with appropriate libraries and implementing own modules. We will discuss most important Python Enhancement Proposals (PEP) and how these can help you write cleaner code. You will learn how to use a code linter and code formatter. Common pitfalls in Python will be explained with examples. We will demonstrate typical “bad programming” and how to code the examples in a more pythonic way.


Basic Python knowledge is required. Participants need a laptop/PC with a working Python installation.

Learning objectives

After the course participants will be able to

Time and place

The course takes place in the Mathematikon, room 5/104 (conference room).

Course date: June 7th 2023, 9:00AM - 1:00PM

Course content

  1. PEP recommendations
  2. Linting
  3. Code formatting
  4. Write better code: Pitfalls
  5. Write better code: Examples

Additional Topics

For general coding best practices, you should always put your source code under version control, implement tests and a documentation, and also add a license to your code. It is not possible to discuss all of this in a short course - here we only cover very Python-specific content. The SSC offers tailored courses that you can participate in. There is also a block course that touches on all these aspects; the block course takes place every year in early March.