Python Basic and Advanced (19.10.2020 - 22.10.2020)


This is a preliminary list of very basic topics. The advanced part of the training is under discussion. Please send feedback/suggestions to

  • Variables and Types

    • Numerical types such as integer, floating point, boolean

    • Sequential types such as list, tuple, string

    • Indexing, slicing and other operations on sequential types

    • Associative types such as dictionaries and sets

    • Mutable versus immutable

  • Control Flow

    • if

    • while

    • for: more about iteration

  • Functions

    • Why and how

    • Parameters passing: positional versus keyword parameters, default parameters

    • Return values

  • Exception Handling

    • The exception hierarchy in the standard library

    • How to define custom exception classes

    • Raising exceptions, and reacting on them

  • Strings — Advanced Features

    • String methods

    • Formatting

    • Encoding: what it is, and how Python solves encoding problems

  • File I/O

    • Opening and/or creating files

    • Reading and writing

  • Advanced Topics

    • Database Programming

    • Web Programming with Flask

Additional Topics, brought in by Thomas

  • Programmverweise mit import XY und Aufruf von XY.ZAB

  • JSON Handling

  • Exception Handling

  • with open(eventCodeFile, ‘r’) as f:

    definedLISAEvents = json.load(f)[‘event_ids’]

  • print (f’bla{variable}blubb’} : was macht das f hier? (habe gesehen, eine verbesserte Stringformatierung in Python3?)


  • Klassen und deren Aufruf im .py Code

  • Headerfiles (.h) verwenden

  • from lib import *

  • .lst Files (Listen?)

  • Socket module

  • Shell script inclusion

  • Code Snippet: “@cs.CALLBACKFUNC” was macht das?


Day 2

  • Observation by Thomas: “as opposed to C# I need to define a function before I can use it”

    Longish answer …

    • Variables are names that refer to objects

    • def is only a statement: creates a function object, and points a name (the function name to it)

    • Cannot use a name that is not there

    • Show how to delete (and resurrect) the int type

  • Exercises: Lists, Loops, Functions

    • Exercise 2: uniq().

      • TODO: Screenplay

        • Complicated iteration over outputsequence, only to determine membership. First with a flag, then with an else clause.

        • in operator on outputsequence

        • Performance: using a set for have-ness

    • Exercise 3: join(). Sketch multiple ways to solve the problem.





  • for loops

  • Generators: Iteration and Generators

    • TODO: reference fibo-*.py files

Day 3

  • Comprehension expressions

    • List comprehension, from More on Lists (live hacking here)

    • Generator expression (live hacking here

    • Dictionary comprehension (live hacking here)

  • File IO

    • File I/O

    • The with statement: context managers

  • Group exercise

    A CAN bus log is gathered by software running on a device. That log contains CAN frames, basically. It has CSV format, suitable for analysis with Excel. One wants to automate the process of log analysis, at least to a certain extent.

    • Start with the csv module: read the log file, print the content of each row. Iteration, basically, and some tuple unpacking.

    • Sideway: encoding. The logfile is in cp1252 format.

Day 4

  • Plan

    • Modules: create a module holding the CSV reading function (returns a list of such Message objects). Show the different forms of import.

    • Format a message list to JSON

    • Cut out a time interval from a larger list

    • Show how CAN bus programming is done in Linux and Python, using the socket module.

  • Class Message to hold rows

  • Function to read CSV into a list of Message objects

  • Explain **kwargs, see here for more. TODO: link to DictReader example in exercises.