4 ms·
that has explained the mechanics of kwargs, but not explained why we would use kwargs. I hardly ever use kwargs because I think they make the source code hard t
by tlarkworthy 13y ago
that has explained the mechanics of kwargs, but not explained why we would use kwargs. I hardly ever use kwargs because I think they make the source code hard to read.
I think they are useful for systems with big configurations (that grow with features during development). I give every customizable function a reference to the big master config dict. Still not sure if that's a good design or not ...
- andrewcooke 13y agokwargs are useful when you don't know in advance what the argument names will be. for example, writing a proxy or decorator that is used on multiple signatures. or implementing some kind of trace facility where you want to log variable names and values.
- gizmo686 13y agoI've used a couple of times for high-order functions. For example, I was playing around with sound generation and decided to create a 'stream' object. Instances of this object were defined by a function that generates the sound wave. This meant that the constructor took a parameter a somewhat generic function. I also found that some of my generator functions could take arguments themselves, such as pitch. Having args and *kwargs allows you to pass these arbitrary variables through.