Je veux rendre ce code compatible avec python2-3:Comment faire une logique basée sur `unicode` compatible avec 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')
Il n'y a pas unicode
ou decode
sur str
de type en python 3. Qu'est-ce que est la meilleure solution pour rendre ce code python2-3 compatible?