Unicode, stdout, and stderr
wxjmfauth at gmail.com
wxjmfauth at gmail.com
Tue Jul 22 02:54:01 EDT 2014
Le mardi 22 juillet 2014 08:18:08 UTC+2, Frank Millman a écrit :
> Hi all
>
>
>
> This is not important, but I would appreciate it if someone could explain
>
> the following, run from cmd.exe on Windows Server 2003 -
>
>
>
> C:\>python
>
> Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit
>
> (In
>
> tel)] on win32
>
> Type "help", "copyright", "credits" or "license" for more information.
>
> >>> x = '\u2119'
>
> >>> x # this uses stderr
>
> '\u2119'
>
> >>> print(x) # this uses stdout
>
> Traceback (most recent call last):
>
> File "<stdin>", line 1, in <module>
>
> File "C:\Python34\lib\encodings\cp437.py", line 19, in encode
>
> return codecs.charmap_encode(input,self.errors,encoding_map)[0]
>
> UnicodeEncodeError: 'charmap' codec can't encode character '\u2119' in
>
> position
>
> 0: character maps to <undefined>
>
> >>>
>
>
>
> It seems that there is a difference between writing to stdout and writing to
>
> stderr. My questions are -
>
>
>
> 1. What is the difference?
>
>
>
> 2. Is there an easy way to get stdout to behave the same as stderr?
>
>
>
%%%%%%%%%%
This is an example of what I explained in my
last msg in the "Python 3 is killing Python".
Quote of my comment:
"Generally, speaking, this is a perpetual annoyment
(to be polite) in Python. Python is always attempting
to find a solution for the "Python user", to enforce a
coding usage instead of letting the user/programmer
doing the task correctly.
I'm not alone to think like this and I have seen
many times people complaining about this."
----
Something different.
>>> x = '\u2119'
>>> x # this uses stderr
This not stderr, but stdout (I doubt you redirected it).
What you see is the *representation* of x
>>> print(x) # this uses stdout
Correct. This is supposed to print, understand desplay,
the "x as litteral" (I do not find a proper name).
Solution:
Work properly. Undestand the coding of chars eco-system as a whole
correctly.
In short: *encode*
I explained that many times (including on wx-list).
jmf
More information about the Python-list
mailing list