[Tutor] simple unicode question

Danny Yoo dyoo at hashcollision.org
Sat Aug 23 03:07:15 CEST 2014


Hi Albert,

Just following up: I consider the 2 (or 3) arg form of unicode() to be
a design flaw in the Standard Library.  It's redundant because the
bytes type already has a decode() method:

    https://docs.python.org/3/library/stdtypes.html#bytes.decode


So I would personally write convert() like this:

######################################
def convert(data):
    if isinstance(data, float):
        return unicode(data)
    if isinstance(data, bytes):
        return data.decode("utf-8")
    raise ValueError("Unexpected data", data)
######################################


More information about the Tutor mailing list