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.

Answer from John La Rooy on Stack Overflow
🌐
Python documentation
docs.python.org › 3 › howto › unicode.html
Unicode HOWTO — Python 3.14.7 documentation
If you pass a Unicode string as the path, filenames will be decoded using the filesystem’s encoding and a list of Unicode strings will be returned, while passing a byte path will return the filenames as bytes. For example, assuming the default filesystem encoding is UTF-8, running the following program: fn = 'filename\u4500abc' f = open(fn, 'w') f.close() import os print(os.listdir(b'.')) print(os.listdir('.'))
🌐
PyPI
pypi.org › project › Unidecode
Unidecode · PyPI
This is a Python port of Text::Unidecode Perl module by Sean M. Burke <sburke@cpan.org>. This library contains a function that takes a string object, possibly containing non-ASCII characters, and returns a string that can be safely encoded to ASCII: >>> from unidecode import unidecode >>> unidecode('kožušček') 'kozuscek' >>> unidecode('30 \U0001d5c4\U0001d5c6/\U0001d5c1') '30 km/h' >>> unidecode('\u5317\u4EB0') 'Bei Jing '
🌐
GitHub
gist.github.com › seanh › 0a56cd528714496625662dd9136d0cd3
Unicode in Python · GitHub
Literal strings are ASCII-encoded ... byte strings into UTF-8 instead of ASCII. A from __future__ import unicode_literals turns literal strings into unicode instead of byte strings....
🌐
Linode
linode.com › docs › guides › how-to-use-unicode-in-python3
Using Unicode in Python 3 | Linode Docs
March 20, 2023 - Python provides many additional functions and libraries to help developers work with Unicode. The most relevant library is unicodedata. It allows developers to extract more information, such as the official name or code point, about each Unicode character. This library can be imported using the following Python directive.
🌐
UW PCE
uwpce-pythoncert.github.io › SystemDevelopment › unicode.html
Unicode in Python 2 — System Development With Python 2.0 documentation
Python 2.6 and above have a nice feature to make it easier to use unicode everywhere · from __future__ import unicode_literals · After running that line, the u'' is assumed ·
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-work-with-unicode-in-python
How To Work with Unicode in Python | DigitalOcean
The tutorial will cover the basics of Unicode in Python and how Python interprets Unicode characters. It covers the concepts of unicodedata and how to use th…
Find elsewhere
🌐
AskPython
askpython.com › python-modules › unicode-in-python-unicodedata
Unicode In Python - The unicodedata Module Explained - AskPython
February 16, 2023 - If not found, then Keyerror is raised. import unicodedata print (unicodedata.lookup('LEFT CURLY BRACKET')) print (unicodedata.lookup('RIGHT SQUARE BRACKET')) print (unicodedata.lookup('ASTERISK')) print (unicodedata.lookup('EXCLAMATION MARK'))
🌐
Python
docs.python.org › 3.0 › howto › unicode.html
Unicode HOWTO — Python v3.0.1 documentation
The following program displays some information about several characters, and prints the numeric value of one particular character: import unicodedata u = chr(233) + chr(0x0bf2) + chr(3972) + chr(6000) + chr(13231) for i, c in enumerate(u): print(i, 'x' % ord(c), unicodedata.category(c), end=" ...
🌐
Python
docs.python.org › 3 › library › unicodedata.html
unicodedata — Unicode Database
This module provides access to the Unicode Character Database (UCD) which defines character properties for all Unicode characters. The data contained in this database is compiled from the UCD versi...
🌐
pytz
pythonhosted.org › kitchen › unicode-frustrations.html
Overcoming frustration: Correctly using unicode in python2 — kitchen 1.2.1 documentation
The kitchen library provides a wide array of functions to help you deal with byte str and unicode strings in your program. Here’s a short example that uses many kitchen functions to do its work: #!/usr/bin/python -tt # -*- coding: utf-8 -*- import locale import os import sys import unicodedata from kitchen.text.converters import getwriter, to_bytes, to_unicode from kitchen.i18n import get_translation_object if __name__ == '__main__': # Setup gettext driven translations but use the kitchen functions so # we don't have the mismatched bytes-unicode issues.
🌐
GeeksforGeeks
geeksforgeeks.org › python › unicode_literals-in-python
unicode_literals in Python - GeeksforGeeks
June 21, 2021 - As in python2, the default encoding is ASCII we need to switch the encoding to utf-8. ... from __future__ import unicode_literals # creating variables to holds # the letters in python word.
🌐
Python-future
python-future.org › unicode_literals.html
Should I import unicode_literals? — Python-Future documentation
The code needs to be changed to ... a native string literal (str type on both platforms). This can be worked around as follows: >>> from __future__ import unicode_literals >>> ......
🌐
Python
docs.python.org › 2 › howto › unicode.html
Unicode HOWTO — Python 2.7.18 documentation
The following program displays some information about several characters, and prints the numeric value of one particular character: import unicodedata u = unichr(233) + unichr(0x0bf2) + unichr(3972) + unichr(6000) + unichr(13231) for i, c in enumerate(u): print i, 'x' % ord(c), unicodedat...
🌐
CKAN
docs.ckan.org › en › 2.9 › contributing › unicode.html
Unicode handling — CKAN 2.9.11 documentation
For more information on string prefixes please refer to the Python documentation. ... The unicode_literals future statement is not used in CKAN. When opening text (not binary) files you should use io.open instead of open. This allows you to specify the file’s encoding and reads will return Unicode instead of ASCII: import io with io.open(u'my_file.txt', u'r', encoding=u'utf-8') as f: text = f.read() # contents is automatically decoded # to Unicode using UTF-8
🌐
Real Python
realpython.com › python-encodings-guide
Unicode & Character Encodings in Python: A Painless Guide – Real Python
May 20, 2019 - Python 3 source code is assumed to be UTF-8 by default. This means that you don’t need # -*- coding: UTF-8 -*- at the top of .py files in Python 3. All text (str) is Unicode by default. Encoded Unicode text is represented as binary data (bytes).
🌐
YouTube
youtube.com › watch
Python and Unicode characters - YouTube
What is Unicode? How can we insert Unicode characters into strings? What's the difference between \x, \u, and \U? How can we insert characters with their nam...
Published: March 23, 2022
🌐
Python Cheat Sheet
pythonsheets.com › notes › basic › python-unicode.html
Unicode — Python Cheat Sheet
Note that the early Python versions (3.0-3.2) do not support the u prefix. In order to ease the pain to migrate Unicode aware applications from Python 2, Python 3.3 once again supports the u prefix for string literals.
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › functions › unicode.html
unicode — Python Reference (The Right Way) 0.1 documentation
If no optional parameters are given, unicode() will mimic the behaviour of str() except that it returns Unicode strings instead of 8-bit strings.