2 ms·
"7" May be because getattr (at least) works the other way around, instead raising an exception if not found and no default specified. I'm sure many people can't
by ris 12y ago
"7" May be because getattr (at least) works the other way around, instead raising an exception if not found and no default specified. I'm sure many people can't always remember which works which way.
- tomp 12y agoThere would be no purpose in the `get()` function if it raised an exception if the key wasn't there - that's how `[]` works. On the other hand, `getattr` is IMO mostly used for situations where you don't know what properties exist on an object, so you can't just use the dot notation.