Created
November 20, 2012 15:18
-
-
Save my8bird/4118540 to your computer and use it in GitHub Desktop.
Python helpers for common cases
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
# 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