Encoding of String

Fredrik Lundh fredrik at pythonware.com
Mon Nov 4 13:35:21 EST 2002


Thomas Guettler wrote:

> 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()"?

unicode string don't have an encoding: they contain Unicode
characters, not encoded data.

(this is no different from reading an integer from, say, a
2-byte big endian field in a binary structure.  once you've
converted it to an integer, it's an integer, not a bunch of
bytes).

</F>





More information about the Python-list mailing list