Skip to content

Instantly share code, notes, and snippets.

Created May 31, 2013 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/725326d048e93066f8d0 to your computer and use it in GitHub Desktop.
Save anonymous/725326d048e93066f8d0 to your computer and use it in GitHub Desktop.
Instead of:
try:
app.memcache.delete(cache_key)
except AttributeError:
try:
env['swift.cache'].delete(cache_key)
except (KeyError, AttributeError):
pass
How about:
memcache = getattr(app, 'memcache', None) or env.get('swift.cache')
if memcache:
memcache.delete(cache_key)
Less than half the lines, no try/except overhead (albeit that's tiny), and no
repeated .delete call code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment