Python STILL prints the wrong international letters

Stephen D Evans stevee at recombinant.demon.co.uk
Fri May 18 15:49:55 EDT 2001


I have experienced similar problems the the British currency symbol. CodePage
850 seems to work regardless of the current locale setting. I ignore the
specifications and the theory - I use what works.

Assuming that you have Python 2.0 or greater. Try the following code (the
encodings are in the Python\Lib\encodings\ directory):


#
s = 'æøåÆØÅ'

for c in s:
    print ord(c),
print

s = u''.join(map(unichr, map(ord, s)))

for c in s:
    print ord(c),
print

for encoding in (
    'cp037', 'cp1026',
    'cp437', 'cp500', 'cp737', 'cp775', 'cp850',
    'cp852', 'cp855', 'cp860', 'cp861', 'cp862',
    'cp863', 'cp865', 'cp866',
    'iso8859_10', 'iso8859_13', 'iso8859_14', 'iso8859_15',
    'iso8859_2', 'iso8859_3', 'iso8859_4', 'iso8859_5', 'iso8859_6',
    'iso8859_7', 'iso8859_9', 'koi8_r', 'latin_1',

    'cp1250', 'cp1251', 'cp1252', 'cp1253', 'cp1254', 'cp1255',
    'cp1256', 'cp1257', 'cp1258',
    'cp856', 'cp857', 'cp864', 'cp869', 'cp874',
    ):
    print encoding, s.encode(encoding)
#
----
Stephen D Evans





Max Møller Rasmussen wrote:

> Come on :-)
>
> Is there really no one that knows why this happens? I have spend a long time
> searching the docs, but to no avail.
>
> I have looked through the string module, the Unicode module, and the locale
> module but nothing promising yet.
>
> The locale on my machine is set to Danish.
>
> It happens both when I print to the Interactive window and to a file.
>
> I don't need a fulle solution, just a hint as to where I can look to solve
> the problem.
>
> Regards Max M
>
> > From: Max Møller Rasmussen [mailto:maxm at normik.dk]
>
> > When I try to print the Danish letters æøå I get garbage instead.
> > >>> print 'æ-ø-å-Æ-Ø-Å'
> > æ-ø-Ã¥-Ã?-Ã~-Ã...
> >
> > Has anybody got an idea as to how I can avoid this?
> >
> > Win2K
> > Python 2.0 (Activestate)




More information about the Python-list mailing list