Skip to content

Instantly share code, notes, and snippets.

@my8bird
Created November 20, 2012 15:18
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 my8bird/4118540 to your computer and use it in GitHub Desktop.
Save my8bird/4118540 to your computer and use it in GitHub Desktop.
Python helpers for common cases
# I found this is a blog post several weeks ago and meant to share but have since lost the article.
# Two simple defines we can use in code to better determine what is going on without doing None checks
Omitted = object()
Undefined = object()
# ---- Usage ---- #
# Admittedly,this is contrived but think of case where you can
# call a function with or without a value and None is allowed.
def update(self, name = Omitted, description = Omitted):
if name is not Omitted:
self.name = name
if description is not Omitted:
self.description = description
def getValue(self, key):
# Check the cache
value = self.cache.get(key, Undefined)
if value is not Undefined:
return value
# ... build the actual value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment