Re: open: 'ascii', 'backslashreplace' not behaving as expected - why?
Lawrence D’Oliveiro <[email protected]>
| Newsgroups | comp.lang.python |
|---|---|
| Organization | A noiseless patient Spider |
| Message-ID | <[email protected]> |
On Sat, 8 Aug 2026 00:38:24 -0000 (UTC), Veek M wrote:
> So in kate, i Ctrl-Shift-U and type ffff to enter a unicode
> codepoint of 0xffff. Then at the REPL prompt i do
> fh = open('/tmp/x', 'rt', -1, 'ascii', 'backslashreplace', None)
>
> and i get
> fh.readline()
> '\\xef\\xbf\\xbf\n'
>
> Since I wrote two bytes 0xff and 0xff into Kate - why am i getting
> 0xef 0xbf and 0xbf ?
Python 3.14.6 (main, Jun 10 2026, 18:54:31) [GCC 15.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> b'\xef\xbf\xbf\n'.decode()
'\uffff\n'