Reputation: 13
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
Upvotes: 1
Views: 1070
Reputation: 295403
Regular strings in Python 3 are unicode. You have to go out of your way in Python 3 to get a bytestring (non-Unicode).
Upvotes: 2