Wednesday, June 12, 2013

Finding if a python object is a string, either unicode or not.

Problem: you want to test to see if an object is a string or not. However your input could either be Python's 'str' type or the 'unicode' type

Solution: Use basestring
 e.g.: isinstance(o, basestring)

No comments:

Post a Comment