Is there a way to tidy-up the following code, rather than a series of nested try/except statements?
try: import simplejson as json except ImportError: try: import json except ImportError: try: from django.utils import simplejson as json except: raise 'Requires either simplejson, Python 2.6 or django.utils!'
I found the following function at http://mail.python.org/pipermail/python-list/2007-May/441896.html. It seems to work quite well, and I’m pretty sure the way its importing won’t stomp on any existing imports you might already have.
I know this seems like more code, but the function is reusable elsewhere if you’re doing a lot of this.