float to unicode question

Erik Max Francis max at alcyone.com
Wed Feb 12 19:32:11 EST 2003


gabor wrote:

> this works:
> a = str(14.34)
> 
> this works:
> a = unicode(14.34)
> 
> this doesn't work:
> a = unicode(14.34,'iso-8859-1')
> 
> why?
> i have to do:
> a = unicode(string(14.34),'iso-8859-1')

[You meant str(14.34).]

The reason is because that second argument (and indeed, the third) is
_only_ for specifying the encoding, and that only makes sense when what
you're passing it is a string.

unicode(14.34) works just fine, but "interpret this float as a Latin-1
string" doesn't make sense, because a float ain't a string.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ If you can't fight and you can't flee, flow.
\__/ Robert Elliot
    Physics reference / http://www.alcyone.com/max/reference/physics/
 A physics reference.




More information about the Python-list mailing list