I want to make this code compatible with python2-3 :
def normalize_text(text, ignore_characters=''):
if type(ignore_characters) not in [list, str, unicode]:
ignore_characters = ''
if type(ignore_characters) == str:
ignore_characters = ignore_characters.decode('utf-8')
if type(ignore_characters) == list:
new_ignore_characters = []
for item in ignore_characters:
if type(item) == str:
new_ignore_characters.append(item.decode('utf-8'))
elif type(item) == unicode:
new_ignore_characters.append(item)
ignore_characters = new_ignore_characters
if type(text) == str:
text = text.decode('utf-8')
There is no unicode
or decode
on str
type in python 3. What is the best workaround to make this code python2-3 compatible?