Ich möchte mit python2-3 dieser Code kompatibel machen:Wie Logik machen, basierend auf `unicode` kompatibel mit 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')
Es gibt keine unicode
oder decode
auf str
Typ in Python 3. Was ist die beste Problemumgehung, um diesen Code python2-3 kompatibel zu machen?