Albert-Jan Roskam <fo...@yahoo.com.dmarc.invalid> Wrote in message: > Hi, > > I have data that is either floats or byte strings in utf-8. I need to cast > both to unicode strings. I am probably missing something simple, but.. in the > code below, under "float", why does [B] throw an error but [A] does not? > >..........
>>>> unicode(value, sys.getdefaultencoding()) # [B] > > Traceback (most recent call last): > File "<pyshell#22>", line 1, in <module> > unicode(value, sys.getdefaultencoding()) > TypeError: coercing to Unicode: need string or buffer, float found >>>> unicode(value, "utf-8") > # (... also TypeError) > Unicode has no encoding, so trying to specify one during a float conversion is nonsensical. Only byte-strings have encodings. You decode them to Unicode, and the result has no encoding. -- DaveA _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor