Holy snakes, #python! That's some gotcha. Did you expect this behavior? Why?


TL;DR: if you create an object (an array or a class instance) in the declaration of a function as a default argument parameter, python creates it as it creates the function and then reuses it for subsequent calls.

That's great for atomic counters, but terrible for suppliers.


@aeveltstra Yeah, that's bitten a few people I know, especially when they're first learning the language. :/

Sign in to participate in the conversation

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!