Python-best-practices-course
Material for the course “Python best practices”, Scientific Software Center, Heidelberg University
Inga Ulusoy, December 2024
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 through implementing your own scripts, modules and packages. We will discuss some fundamental 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.
Prerequisites
Basic Python knowledge is required. Participants need a laptop/PC with a working Python environment installed, ideally in an IDE, and a GitHub account as we are using GitHub classrooms.
Learning objectives
After the course participants will be able to
- Understand the basic PEP recommendations
- Use a linter and code formatter to ensure following of the guidelines
- Write better=more readable code
- Avoid bugs through best practices for example in passing keyword arguments
Time and place
The course takes place in the conference room of the Mathematikon Bauteil A (room 5/104).
Course date: December 16th 2024, 9:00AM - 1:00PM
Course content
- PEP recommendations
- Linting
- Code formatting
- Write better code: Pitfalls
- 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 present 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 February/March.