Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added get(key, default=..) method to AttributeProxy, to allow dict like checking of existing variables #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

CaerphillyMediaLtd
Copy link

I'm not sure how welcome this is, but we've added a dict-like get method to our codebase so that we can perform typical dictionary checking for keys, e.g.:

time = response.resources.get('lastTime', '01/01/2001')

Rather than having to check if lastTime exists, then setting a default if it doesn't. As with dict it's also very useful for stringing together values:

name = resources.get('person', {}).get('name', 'Unknown')

Which dramatically improves readability, and allows you to easily default to one value if one or both of person and name don't exist.

I think this is a much more pythonic way of handling it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant