Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
The dumps param in simplejson.dumps is often helpful, but sometimes you want to quickly pass in multiple default actions. This should help.
def compose_defaults(*defaults):
'''I got annoyed that simplejson.dumps doesn't let you pass multiple
defaults. So here's this.'''
def new_default(obj):
for default in defaults:
return default(obj)
raise TypeError("no default functions succeeded")
return new_default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment