Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #74039

Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position, to print out the file contents to stdout,

Newsgroups comp.lang.python
Date 2014-07-06 11:14 -0700
References <b447a73e-cad2-4448-abff-675a3b387e9b@googlegroups.com> <57444726-c79e-499c-aff6-5d268448035f@googlegroups.com> <6a41f25e-2025-4f1a-ad9d-4458fc804b63@googlegroups.com> <mailman.11546.1404663297.18130.python-list@python.org> <4ebc3166-f17e-482b-ad6c-f109db4cad2d@googlegroups.com>
Message-ID <53aba448-ac52-46c7-99c0-906e8bbc0e0d@googlegroups.com> (permalink)
Subject Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position, to print out the file contents to stdout,
From wxjmfauth@gmail.com

Show all headers | View raw


Le dimanche 6 juillet 2014 18:53:34 UTC+2, Rick Johnson a écrit :

[...]
> 
> 
> Seems like she'd better do the decoding before printing

No

> [...], or
> 
> am i wrong again?

Yes


>>> s = 'abc需'
>>> sys.stdout.encoding
'<unicode>'
>>> print(s)
abc需
>>> sys.stdout.encoding = 'cp437'
>>> sys.stdout.encoding
'cp437'
>>> print(s)
Traceback (most recent call last):
  File "<eta last command>", line 1, in <module>
  File "D:\jm\jmpy\eta\eta40beta2\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 characters in position 4-5: 
character maps to <undefined>
>>> print(s.encode(sys.stdout.encoding, 'replace'))
'abcé??'
>>> sys.stdout.encoding = 'cp850'
>>> sys.stdout.encoding
'cp850'
>>> print(s)
Traceback (most recent call last):
  File "<eta last command>", line 1, in <module>
  File "D:\jm\jmpy\eta\eta40beta2\etastdio.py", line 158, in write
    s = s.encode(self.pencoding).decode('cp1252')
  File "C:\Python32\lib\encodings\cp850.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode characters in position 4-5: 
character maps to <undefined>
>>> print(s.encode(sys.stdout.encoding, 'replace'))
'abcé??'
>>> # and so on
>>> sys.stdout.encoding = 'cp1252')
  File "<eta last command>", line 1
    sys.stdout.encoding = 'cp1252')
                                  ^
SyntaxError: invalid syntax
>>> # oops
>>> sys.stdout.encoding = 'cp1252'
>>> print(s)
abc需
>>> sys.stdout.encoding = 'mac-roman'
>>> print(s)
abcŽÏÛ
>>> print(s.encode(sys.stdout.encoding, 'replace'))
'abc需'
>>> sys.stdout.encoding = 'utf-8'
>>> print(s.encode(sys.stdout.encoding, 'replace'))
'abc需'
>>> sys.stdout.encoding = 'utf-16-le'
>>> print(s.encode(sys.stdout.encoding, 'replace'))
'abc需'
>>> 
>>> sys.stdout.encoding = 'utf-32-be'
>>> print(s.encode(sys.stdout.encoding, 'replace'))
'abc需'
>>>

jmf

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position,  to print out the file contents to stdout, gintare <g.statkute@gmail.com> - 2014-07-06 01:45 -0700
  Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position,  to print out the file contents to stdout, gintare <g.statkute@gmail.com> - 2014-07-06 02:05 -0700
    Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position,  to print out the file contents to stdout, Dave Angel <davea@davea.name> - 2014-07-06 08:57 -0400
    Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position,  to print out the file contents to stdout, Rick Johnson <rantingrickjohnson@gmail.com> - 2014-07-06 07:52 -0700
      Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position,  to print out the file contents to stdout, Terry Reedy <tjreedy@udel.edu> - 2014-07-06 12:14 -0400
        Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position,  to print out the file contents to stdout, Rick Johnson <rantingrickjohnson@gmail.com> - 2014-07-06 09:53 -0700
          Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position,  to print out the file contents to stdout, wxjmfauth@gmail.com - 2014-07-06 11:14 -0700
            Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position,  to print out the file contents to stdout, Rick Johnson <rantingrickjohnson@gmail.com> - 2014-07-06 12:37 -0700
              Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position,  to print out the file contents to stdout, wxjmfauth@gmail.com - 2014-07-06 23:58 -0700

csiph-web