Encoding of String

Oren Tirosh oren-py-l at hishome.net
Mon Nov 4 12:44:52 EST 2002


On Mon, Nov 04, 2002 at 05:40:36PM +0100, Thomas Guettler wrote:
> Hi!
> 
> Is there a way to get the encoding of a string?
> 
> Suppose I do:
> 
> mystring="blu"
> ustring=unicode(mystring, "utf-8")
> 
> later I want to know which encoding ustring has:
> ustring.getEcoding() --> "utf-8"
> 
> Is there something like "getEcoding()"?

A unicode object is always assumed to be encoded in the ISO 10646 
character set (also known as just Unicode). The original encoding
is gone when you decode it. If you have to export the data back into 
the unfriendly world of 8 bit legacy you have to choose an encoding 
depending on the limitations of your environment. The appropriate 
encoding may or may not be the same encoding it had when you got it.

	Oren






More information about the Python-list mailing list