Created
June 5, 2013 05:12
-
-
Save eedeep/5711756 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mydict = {'mykey': 'foo', } | |
class MyObj(object): | |
thing = 'whatever' | |
myobj = MyObj() | |
val = None | |
try: | |
val = getattr(myobj, 'thing', mydict['nonexistent']) | |
except KeyError as e: | |
val = getattr(myobj, 'thing', None) | |
if not val: | |
raise e | |
print val |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment