Skip to content

Instantly share code, notes, and snippets.

@wrefactor
wrefactor / generators_py313.py
Created September 1, 2025 14:16
Using generator functions to represent simulations
"""
Using generator functions to represent simulations
==================================================
A quick example of how to model a long/complex calculation using a generator function (a function containing
'yield') in Python. In the example below, we set-up a calculation; get intermediate results from it; send
new data to it, and - using a new feature in Python 3.13 - get a finished result at the end.
Ultimately, do what's clearest, and easiest to understand and maintain.