python3 - the hardest hello world ever ?

Paul Boddie paul at boddie.org.uk
Wed Oct 15 12:21:41 EDT 2008


On 15 Okt, 17:59, Helmut Jarausch <jarau... at skynet.be> wrote:
> Paul Boddie wrote:
> > What does sys.stdout.encoding say? In Python 2.x, at least, that
>
> It says  ansi_x3.4-1968

That's ASCII, yes.

> Where can I change this?

What's your locale? I can provoke the same setting if I run a Python
program like this:

LC_ALL=en_US.ascii python xxx.py

Are you running some kind of GNU/Linux distribution or something else?
If the former, have you installed various language/locale packages? If
you're not sure, which language or country did you select when
installing or configuring your system? This may seem like an odd line
of questioning, but UNIX-like systems have a history of treating
everything as bytes, which works acceptably until you have to take a
stand on what those bytes mean.

Another important question: what does Python 2.x do with the following
program...?

import sys
print sys.stdout.encoding
print u"\xe6\xf8\xe5"

You should get three Scandinavian characters if the encoding and
locales match. Otherwise, you'll either get a different output
(indicating a mismatch) or an error (indicating that the environment
cannot handle the characters output by the program). Sometimes you can
persuade a terminal to use a different character set, and this might
help, too.

Paul



More information about the Python-list mailing list