Created
January 25, 2019 10:53
-
-
Save Ch00k/87b7550e710db95bd67b6a8b27b9a40f to your computer and use it in GitHub Desktop.
dict lookup log if None
This file contains hidden or 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
import logging | |
d = {'foo': 42} | |
def log_if_none(message): | |
logging.warning(message) | |
foo = d.get('foo', log_if_none("No key foo")) | |
bar = d.get('bar', log_if_none("No key bar")) | |
baz = d.get('baz', log_if_none("No key baz")) | |
print(foo, bar, baz) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment