3 ms·
Well, yeah, but you could implement it without __dict__ just by doing something like: for attr, val in locals().items(): setattr(self, attr, val) It sti
by chc 10y ago
Well, yeah, but you could implement it without __dict__ just by doing something like:
for attr, val in locals().items():
setattr(self, attr, val)
It still feels pretty un-Pythonic either way.
- jsmthrowaway 10y agoBecause it is. There is zero reason to be clever here. Yeah, you have to be explicit in __init__. We are all used to it. The "a," "b," "c" examples are disingenuous though because you're often validating, enforcing types, converting, deriving other attributes... __init__ is documentation. I read it to understand what's going on.