Hello everyone.

I'm having a problem when outputing UTF-8 strings to a console.
Let me show a simple example that explains it:

$ python -c 'import sys; print sys.stdout.encoding; print u"\xe9"'
UTF-8
é

It's everything ok.
Now, if you're using your python script in some shell script you might have
to store the output in some variable, like this:

$ var=`python -c 'import sys; print sys.stdout.encoding; print u"\xe9"'`

And what you get is:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position
0: ordinal not in range(128)

So, python is not being able to detect the encoding of the output in a
situation like that, in which the python script is called not directly but
around ``.

Why does happen? Is there a way to solve it either by python or by shell
code?

Thanks,
Pedro Abranches
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to