I am currently trying to convert a piece of code from python 2 to python 3 and I cannot find the python 3 equivalent of unicode
:
class NavigableString(unicode_literals, PageElement):
def toEncoding(self, s, encoding=None):
"""Encodes an object to a string in some encoding, or to Unicode.
."""
if isinstance(s, unichr()):
if encoding:
s = s.encode(encoding)
elif isinstance(s, str):
if encoding:
s = s.encode(encoding)
else:
s = unicode_literals(s)
else:
if encoding:
s = self.toEncoding(str(s), encoding)
else:
s = unicode_literals(s)
return s
Regular strings in Python 3 are unicode. You have to go out of your way in Python 3 to get a bytestring (non-Unicode).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.