3 ms·
True, but it saves a relatively small number of chars (~12) and does so at the same time as: A) Giving off a signal that you're dealing with an object rather t
by crdoconnor 10y ago
True, but it saves a relatively small number of chars (~12) and does so at the same time as:
A) Giving off a signal that you're dealing with an object rather than a dict.
B) Making it cumbersome to swap out some of those selectors with variables.
C) Making it difficult to deal with the attribute not being there (with a dict you can say .get("attr2", {}) and it returns a default.
- yeukhon 10y agoI understand. I have another motivation which is getting JSON and wanting a OOP object to mainpluate with. Take AWS' boto3 response. Well documented but the nested response structure gives me a chill and I wish there's a direct object out of the JSON. I instead had to write my own class for the conversion. If I could mainpluate dict like mainpluatig attribute in a class then I could just write my function's contract "input is a response object from X APi" instead of "dict of this form." Quite annoying and I know some people considered what I wish is a bad practice.
- deleted 10y ago[deleted]