For Python 2.x:
try:
basestring # added in Python 2.3
except NameError:
basestring = (str, unicode)
...
if isinstance(foo, basestring):
...
Of course this might not work for Python 3, but I'm quite sure the 2to3 converter will take care of the topic.