Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74977
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2014-07-22 00:07 -0700 |
| References | <mailman.12161.1406009902.18130.python-list@python.org> |
| Message-ID | <c580232e-5b2d-45b7-a957-fab088ec5fa2@googlegroups.com> (permalink) |
| Subject | Re: Unicode, stdout, and stderr |
| From | wxjmfauth@gmail.com |
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?
>
>
>
%%%%%%%%%%%
Again, from my "magic" interactive intepreter.
>>> x = 'a\u2119z'
>>> sys.stdout.encoding
'<unicode>'
>>> x
'aℙz'
>>> sys.stdout.encoding = 'cp437'
>>> print(x)
Traceback (most recent call last):
File "<eta last command>", line 1, in <module>
File "D:\jm\jmpy\eta\eta41beta1\etastdio.py", line 158, in write
s = s.encode(self.pencoding).decode('cp1252')
File "c:\python32\lib\encodings\cp437.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character '\u2119' in position 1:
character maps to <undefined>
>>> print(x.encode(sys.stdout.encoding, 'replace'))
'a?z'
>>> # voilà, no error
jmf
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Unicode, stdout, and stderr "Frank Millman" <frank@chagford.com> - 2014-07-22 08:18 +0200
Re: Unicode, stdout, and stderr wxjmfauth@gmail.com - 2014-07-21 23:54 -0700
Re: Unicode, stdout, and stderr Steven D'Aprano <steve@pearwood.info> - 2014-07-22 06:58 +0000
Re: Unicode, stdout, and stderr "Frank Millman" <frank@chagford.com> - 2014-07-22 09:15 +0200
Re: Unicode, stdout, and stderr Lele Gaifax <lele@metapensiero.it> - 2014-07-22 09:36 +0200
Re: Unicode, stdout, and stderr Akira Li <4kir4.1i@gmail.com> - 2014-07-23 05:01 +0400
Re: Unicode, stdout, and stderr wxjmfauth@gmail.com - 2014-07-23 00:35 -0700
Re: Unicode, stdout, and stderr wxjmfauth@gmail.com - 2014-07-22 00:07 -0700
csiph-web