What happened to Unicode in Python 3?

2

I'm starting to use Python3 slowly. I was running a certain code that I used to run with Python2.7 and got the following error:

  

NameError: name 'unicode' is not defined

So, I understand that unicode does not exist in Python 3. What should I use instead?

    
asked by anonymous 23.11.2016 / 13:29

1 answer

2

According to the answer in the SO of Martjin Pieters Unicode has been renamed to str , which is more intuitive, and the old str has been renamed to bytes . It puts a code to handle when you do not know what the encoding is:

if isinstance(unicode_or_str, str):
    text = unicode_or_str
    decoded = False
else:
    text = unicode_or_str.decode(encoding)
    decoded = True
    
23.11.2016 / 13:59