3 ms·
Mutable arguments are considered harmful; and will probably cause cancer, plague, locusts and other end-of-the-world problems.
by jnoller 17y ago
Mutable arguments are considered harmful; and will probably cause cancer, plague, locusts and other end-of-the-world problems.
- j_baker 17y agoI was under the impression that Python's handling of mutable arguments was actually a feature. Although I must admit, I've never written any code that would use it.
- adw 17y agoYeah, that's more or less what happens. What you'd, admittedly naively, want, though, is a way of saying "a new empty dictionary, please", so you don't wind up having to write this kind of thing: def f(a, d=None): if d is None: d = {} which, okay, it's a minor deal, and I know why it happens, but it's the kind of thing I forget you need to do!