R: unicode to string conversion

Skip Montanaro skip at pobox.com
Fri May 9 10:57:49 EDT 2003


    Skip> u = u'questa \xe8 bella'
    Skip> s = u.encode("iso-8859-1")
    Skip> print s
    Skip> questa è bella

    Luca> maybe i have mispelled my problem ....

    Luca> I would like to transform the unicode string:

    Luca> 	u= u'più'

    Luca> into an usual string:

    Luca> 	s = 'più'

Which is exactly what my answer did.  There is no one best encoding when
converting a unicode object into a plain string object.  Try the above with
the following

    print type(u)
    print type(s)

You'll see that s is a plain string object.  As Jeff Epler pointed out, for
him encoding as utf-8 made more sense because that's what his terminal
application expected.

Skip





More information about the Python-list mailing list