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

medium.com/geekculture/do-not-

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.

Follow

@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
social.coop

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