Issue
I'm aware that I can use: isinstance(x, str)
in python-3.x but I need to check if something is a string in python-2.x as well. Will isinstance(x, str)
work as expected in python-2.x? Or will I need to check the version and use isinstance(x, basestr)
?
Specifically, in python-2.x:
>>>isinstance(u"test", str)
False
and python-3.x does not have u"foo"
Solution
If you're writing 2.x-and-3.x-compatible code, you'll probably want to use six:
from six import string_types
isinstance(s, string_types)
Answered By - ecatmur
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.