Python: modifying imported value
TL;DR: Python statement from module import obj creates a copy of the object in the importing scope. In other words, from module import obj is roughly equivalent to obj = __import__(‘module’).obj. […]
TL;DR: Python statement from module import obj creates a copy of the object in the importing scope. In other words, from module import obj is roughly equivalent to obj = __import__(‘module’).obj. […]
Creation of Python packages underwent a few significant changes in the last 3-4 years. Here’s my note to self to remember what was changed/deprecated when: “Eggs” => “Wheel“ “Eggs” was […]
When serializing a dataclass, by default marshmallow-dataclass emits nulls for all fields that have the value of None. This is not necessariy most of the time and pollutes the resulting […]
TL;DR Python generator expressions can be iterated over only once. I mentally mapped Python generator expressions to C# IEnumerables, which can be iterated over multiple times. In reality, Python generator […]
TL;DR use marshmallow-dataclass. Serializing JSON into dataclasses with validation proved to be unexpectedly difficult. By “validation” here I mean type checking (this must be a valid integer), range checking (this […]
Code: https://github.com/ikriv-samples/logarthmic-fibonacci. Fibonacci sequence is defined as a sequence starting with 0, 1 where each subsequent member is calculated as fib(n) = fib(n-1)+fib(n-2). This yields an infinite sequence 0, 1, […]
In Python, async for uses asynchronous generator to iterate over values. But how is it different from a regular for that uses a generator that yields awaitables? TL;DR: not much, […]
Coming from C# background, I was trying to understand whether Python allows to pass obj.method where ordinary function is expected, and if yes, how could it possibly work. Consider this […]