Encoding of String
Gillou
nospam at bigfoot.com
Tue Nov 5 10:30:17 EST 2002
"Thomas Guettler" <zopestoller at thomas-guettler.de> a écrit dans le message
de news: aq67lr$6fj$06$1 at news.t-online.com...
> 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()"?
>
> thomas
>
>
AFAIK strings (8 bits) don't have any encoding attribute.
Unicode strings are always ISO 10646.
You may get your system's default encoding (the way you should do your 8bit
string I/O) using :
import locale
defaultEncoding = locale.getdefaultlocale()[1]
-> "cp1252" on my Windoz box
-> "iso8859-1" on my FreeBSD box
As I said, it "may" work if the default encoding is properly set, systemwide
or in your user preferences.
--Gilles
More information about the Python-list
mailing list