How can I check if a Python object is a string (either regular or Unicode)?
For a nice duck-typing approach for string-likes that has the bonus of working with both Python 2.x and 3.x:
def is_string(obj):
try:
obj + ''
return True
except TypeError:
return False
wisefish was close with the duck-typing before he switched to the isinstance approach, except that += has a different meaning for lists than + does.