Literal strings are unicode by default in Python3.
Assuming that text
is a bytes
object, just use text.decode('utf-8')
unicode
of Python2 is equivalent to str
in Python3, so you can also write:
str(text, 'utf-8')
if you prefer.
More Related Contents:
- What is the best way to remove accents (normalize) in a Python unicode string?
- UnicodeDecodeError: ‘charmap’ codec can’t decode byte X in position Y: character maps to
- How to set sys.stdout encoding in Python 3?
- “Unicode Error “unicodeescape” codec can’t decode bytes… Cannot open text files in Python 3 [duplicate]
- How can I convert surrogate pairs to normal string in Python?
- How to correct TypeError: Unicode-objects must be encoded before hashing?
- Normalizing Unicode
- Facebook JSON badly encoded
- NameError: global name ‘unicode’ is not defined – in Python 3
- Why doesn’t Python recognize my utf-8 encoded source file?
- Python 3 print() function with Farsi/Arabic characters [duplicate]
- Python 3: How to specify stdin encoding
- Identifier normalization: Why is the micro sign converted into the Greek letter mu?
- requests.get returns 403 while the same url works in browser
- How to encode Python 3 string using \u escape code?
- What is internal representation of string in Python 3.x
- Set encoding in Python 3 CGI scripts
- How to deal with unicode string in URL in python3?
- Python 3 chokes on CP-1252/ANSI reading
- How to make print() output UTF-8 in Python 3.0?
- How can I get 2.x-like sorting behaviour in Python 3.x?
- Powersets in Python using itertools
- Installed module using pip, not found
- How to test Python 3.4 asyncio code?
- Getting value of enum on string conversion
- cx_Oracle error. DPI-1047: Cannot locate a 64-bit Oracle Client library
- How to strip all whitespace from string
- Using Properties in Python classes cause “maximum recursion depth exceeded” [duplicate]
- json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 190) [duplicate]
- ‘is’ operator behaves unexpectedly with floats