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)
You can try this at the beginning of your code:
from __future__ import print_function
import sys
if sys.version[0] == "2":
py3 = False
else:
py3 = True
if py3:
basstring = str
else:
basstring = basestring
and later in the code:
anystring = "test"
# anystring = 1
if isinstance(anystring, basstring):
print("This is a string")
else:
print("No string")