R. David Murray added the comment:
The characters are fine when you read them (that is, they decode correctly to
unicode). They are only invalid when you write them to the windows terminal,
which can't handle all the valid characters that are in the file. The Idle
output window uses a more
John Van Praag added the comment:
According to the documentation of the open function:
errors is an optional string that specifies how encoding and decoding
errors are to be handled–this cannot be used in binary mode. Pass
'strict' to raise a ValueError exception if there is an encoding error
(
Ezio Melotti added the comment:
The problem is not in the reading part, but in the print().
Since the default encoding of your terminal is cp437 and cp437 is not able to
encode the "bad character" (U+2019 RIGHT SINGLE QUOTATION MARK), an error is
raised.
--
nosy: +ezio.melotti
resolut
New submission from John Van Praag :
The declaration errors='replace' works from within IDLE but not at the Windows
command line. I am attaching a program and text file that demonstrate the
problem. The error shows up at the Windows command line as follows:
C:\Users\John\Documents\Python\bug_r