Leget es shet
Leget es shet

Reputation: 13

unicode python 3 equivalent

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

Answers (1)

Charles Duffy
Charles Duffy

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

Related Questions