.. include:: Python (2026-11-11 - 2026-11-13) ================================ .. topic:: Course Info * **Course Material**: :doc:`/trainings/material/soup/python/index` * **Original Agenda**: :doc:`agenda` * **Project on Github**: https://github.com/jfasch/2026-11-11 .. toctree:: :hidden: agenda .. contents:: :local: Day 1: Basics: Variables, Datatypes, (Im)Mutability ... ------------------------------------------------------- On day one, basically everything that's in :doc:`/trainings/material/soup/python/basics/index` 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 (:doc:`(im)mutability ` is one such). Basics ...... Here's all from :doc:`/trainings/material/soup/python/basics/index`; we took that as a reference to find our way back to a more structured course flow. * :doc:`/trainings/material/soup/python/basics/installation` * :doc:`/trainings/material/soup/python/basics/python_0110_blahblah/topic` * :doc:`/trainings/material/soup/python/basics/python_0120_helloworld/topic` * :doc:`/trainings/material/soup/python/basics/python_0125_running/topic` * :doc:`/trainings/material/soup/python/basics/python_0130_syntax_etc/topic` * :doc:`/trainings/material/soup/python/basics/python_0139_commandline_argv/topic` * :doc:`/trainings/material/soup/python/basics/python_0140_variables/topic` * :doc:`/trainings/material/soup/python/basics/python_0150_datatypes_overview/topic` * :doc:`/trainings/material/soup/python/basics/python_0150_datatypes_overview_compound/topic` * :doc:`/trainings/material/soup/python/basics/python_0160_boolean/topic` * :doc:`/trainings/material/soup/python/basics/python_0170_if/topic` * :doc:`/trainings/material/soup/python/basics/python_0193_while/topic` * :doc:`/trainings/material/soup/python/basics/python_0200_sequential_types/topic` * :doc:`/trainings/material/soup/python/basics/python_0210_indexing_slicing/topic` * :doc:`/trainings/material/soup/python/basics/python_0220_for/topic` * :doc:`/trainings/material/soup/python/basics/python_0225_range/topic` * :doc:`/trainings/material/soup/python/basics/python_0250_refs_flat_deep_copy/topic` * :doc:`/trainings/material/soup/python/basics/python_0270_functions/topic` * :doc:`/trainings/material/soup/python/basics/python_0300_strings/topic` * :doc:`/trainings/material/soup/python/basics/python_0310_strings_formatting/topic` * :doc:`/trainings/material/soup/python/basics/python_0320_strings_methods/topic` * :doc:`/trainings/material/soup/python/basics/python_0400_lists/topic` * :doc:`/trainings/material/soup/python/basics/python_0450_dictionaries/topic` * :doc:`/trainings/material/soup/python/basics/python_0460_sets/topic` * :doc:`/trainings/material/soup/python/basics/python_0500_files/topic` * :doc:`/trainings/material/soup/python/basics/python_1000_function_objects/topic` * :doc:`/trainings/material/soup/python/advanced/comprehensions/topic` Exercise Time ............. An exercise was done after lunch, to measure the level of confusion. Outcome: not confused. See :doc:`outcome `. .. toctree:: :hidden: prog-uniq 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. * :doc:`/trainings/material/soup/python/advanced/iteration-generation/python_1010_generators_yield/topic` .. _2026-11-11-day2: Day 2: Project Work ------------------- Kicked off a `group project, maintained on Github `__, and spent the whole day doing test driven development. Project Management .................. * :doc:`/trainings/material/soup/python/swdev/pip/topic` * :doc:`/trainings/material/soup/python/swdev/venv/topic` * :doc:`/trainings/material/soup/python/swdev/pytest/index` File I/O, And Encoding ...................... * :doc:`/trainings/material/soup/python/basics/python_0500_files/topic` * :doc:`/trainings/material/soup/python/misc/encoding/topic` Day 3: Object Oriented Programming, Advanced Topics --------------------------------------------------- Morning Wakeup: ``inspect``, More Comprehensions, Fibonacci Generator ..................................................................... * *Inspecting function signatures*. :ref:`Yesterday <2026-11-11-day2>` we saw what Pytest fixtures are, and how one is requested. Here's the mechanism to *implement* such a mechanism. .. jupyter-execute:: # request "tmpdir" and "monkeypatch" fixtures def test_something(tmpdir, monkeypatch): pass .. jupyter-execute:: # internally to pytest, they look at the *names* of the parameters import inspect print(inspect.signature(test_something).parameters) * More about comprehensions: in addition to ``list`` comprehension that we covered yesterday, there are ``set`` and ``dict`` comprehensions. * :doc:`/trainings/material/soup/python/advanced/comprehensions/topic` Another type of comprehension, syntactically similar to a list comprehension, is a *generator expression*. List comprehension: .. jupyter-execute:: squares = [i**2 for i in range(4)] for sq in squares: print(sq) print(type(squares)) Equivalent generator expression: .. jupyter-execute:: squares = (i**2 for i in range(4)) for sq in squares: print(sq) print(type(squares)) * Show how generators can approach infinity (live-coding the Fibonacci generator) .. literalinclude:: code/fib.py :language: python Object Oriented Programming ........................... .. topic:: More OO Material * :doc:`/trainings/material/soup/python/advanced/oo/index` Continuing with the `course project `__, we discovered the need for classes. * :doc:`/trainings/material/soup/python/advanced/oo/classes-and-dicts/topic` * :doc:`/trainings/material/soup/python/advanced/oo/constructor/topic` * :doc:`/trainings/material/soup/python/advanced/oo/methods/topic` 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: * :doc:`/trainings/material/soup/python/advanced/oo/operator-overloading/topic` More Python Topics .................. .. topic:: Python modules used * :doc:`sys `: ``argv``, ``path`` (Python module search path) * :doc:`os `: low level OS routines like ``os.listdir()`` (look into ``os.walk()`` for something more capable) * :doc:`json `: convert dictionaries (and other builtin types) back and forth * :doc:`pathlib `: mainly used it to show how ``/`` (division) is overloaded to do fancy file system path concatentation. * concurrent.futures ThreadPoolExecutor * :doc:`random ` * :doc:`textwrap `: ``dedent()`` to remove indentation from multiline strings * :doc:`subprocess `: run external programs, examine their exitstatus, capture their output (stdout). 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. * :doc:`/trainings/material/soup/python/advanced/exceptions/topic` * :doc:`/trainings/material/soup/python/advanced/starargs/topic` * :doc:`/trainings/material/soup/python/basics/python_0270_functions/screenplay-scoping` .. _2026-11-11-multithreading: 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) ` - we used C++ instead, where such kinds of mishaps happen on a daily basis. See the coverage of a *Load-Modify-Store Conflict* from :doc:`/trainings/material/soup/cxx/cxx11/multithreading/memory-model/index`, * :ref:`cxx-memory-model-integer-increment-single-thread` * :ref:`cxx-memory-model-integer-increment-not-atomic` * :ref:`cxx-memory-model-integer-increment-mother` * :ref:`cxx-memory-model-integer-increment-lms` Next, we saw how threads in Python are created * :doc:`/trainings/material/soup/python/advanced/multithreading/basics` * :doc:`/trainings/material/soup/python/advanced/multithreading/mutex` (not actually covered) 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 :doc:`python:library/concurrent.futures`. 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 :ref:`multithreading <2026-11-11-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 |:sunglasses:|.