PROGRAMMING
Python
Python from your first script to code you can maintain. Start here if you have never programmed.
0 likes
Likes for this tutorial.
Writing a Custom Iterator Class in Python With __iter__ and __next__
Level: Advanced
A for loop calls iter() once and next() until StopIteration. Write __iter__ and __next__ yourself, avoid the iterator that only works once, and know when a generator in __iter__ does the same job in fewer lines.
6 min read
0 likes
Likes for this tutorial.
Python dataclasses: A Class Without Writing __init__ by Hand
Level: Intermediate
If a class mostly holds data, @dataclass writes __init__, a readable printout and equality for you. Use field(default_factory=list) for lists, __post_init__ for checks and frozen=True for values that must not change.
5 min read
0 likes
Likes for this tutorial.
Writing Your Own Python Context Manager, With a Class or contextlib
Level: Advanced
Write a context manager when something must be undone no matter how the block ends. Build one as a class and with @contextmanager, keep yield inside try/finally, and don't swallow errors by accident.
5 min read