Python (2026-11-11 - 2026-11-13)#

Day 1: Basics: Variables, Datatypes, (Im)Mutability …#

On day one, basically everything that’s in Python: The Language Fundamentals was covered in one way or another. There was already a critical mass of Python knowledge available, so we could jump around and focus on the more important topics ((im)mutability is one such).

Basics#

Here’s all from Python: The Language Fundamentals; we took that as a reference to find our way back to a more structured course flow.

Exercise Time#

An exercise was done after lunch, to measure the level of confusion. Outcome: not confused.

See outcome.

Iterator Protocol, Generators (yield)#

Additionally, we had a look into generators (the exercise outcome linked above contains some of it). In Python, there’s always more to every innocent topic.

Day 2: Project Work#

Kicked off a group project, maintained on Github, and spent the whole day doing test driven development.

Project Management#

File I/O, And Encoding#

Day 3: Object Oriented Programming, Advanced Topics#

Morning Wakeup: inspect, More Comprehensions, Fibonacci Generator#

  • Inspecting function signatures. Yesterday we saw what Pytest fixtures are, and how one is requested. Here’s the mechanism to implement such a mechanism.

    # request "tmpdir" and "monkeypatch" fixtures
    def test_something(tmpdir, monkeypatch): pass
    
    # internally to pytest, they look at the *names* of the parameters
    import inspect
    print(inspect.signature(test_something).parameters)
    
    OrderedDict({'tmpdir': <Parameter "tmpdir">, 'monkeypatch': <Parameter "monkeypatch">})
    
  • More about comprehensions: in addition to list comprehension that we covered yesterday, there are set and dict comprehensions.

    Another type of comprehension, syntactically similar to a list comprehension, is a generator expression.

    List comprehension:

    squares = [i**2 for i in range(4)]
    for sq in squares:
        print(sq)
    print(type(squares))
    
    0
    1
    4
    9
    <class 'list'>
    

    Equivalent generator expression:

    squares = (i**2 for i in range(4))
    for sq in squares:
        print(sq)
    print(type(squares))
    
    0
    1
    4
    9
    <class 'generator'>
    
  • Show how generators can approach infinity (live-coding the Fibonacci generator)

    def fib():
        first, second = 1, 1
        yield first
        yield second
        while True:
            third = first + second
            yield third
            first, second = second, third
    
    for num in fib():
        print(num)
    

Object Oriented Programming#

Continuing with the course project, we discovered the need for classes.

Sideways into operator overvloading that we encountered the dict where objects were ==-compared key-value-wise and not by their identity. There’s always more:

More Python Topics#

As we worked on the project, we started to a number of modules that come with the Python installation (docs linked above), and a stream of additional Python topics flooded in.

Multithreading#

Sadly, it is not easy to omit multithreading from a programming course. To frighten the guys away from it, I began by showing what a race condition is. Race conditions are not easily shown in Python, because of Python’s GIL (Global Interpreter Lock) <https://wiki.python.org/python/archive/GlobalInterpreterLock.html> - we used C++ instead, where such kinds of mishaps happen on a daily basis.

See the coverage of a Load-Modify-Store Conflict from atomic<>: The C++ Memory Model,

Next, we saw how threads in Python are created

When we had modified our project to use threads (to run external programs in parallel), it turned out that it is not easy to communicate exceptions that were raised in a thread to the controlling thread. Switch to something really handy: ThreadPoolExecutor from concurrent.futures — Launching parallel tasks.

Afterword#

Fine course. For one, the guys were really smart. I encountered a culture that made the course a bi-directional communication, and less of a frontal lecture. Also, I tried to confuse them as much as I could, but mostly failed (I may have succeeded with the multithreading section though). For another, the course took place in my hometown; travel expenses in both monetary and psychic form were kept to a minimum 😎.