Re: open: 'ascii', 'backslashreplace' not behaving as expected - why?

Veek M <[email protected]>
Newsgroups gmane.comp.python.general
Organization A noiseless patient Spider
Message-ID <[email protected]>
On Sat, 8 Aug 2026 04:25:43 -0000 (UTC), Veek M wrote:

> On Sat, 8 Aug 2026 04:22:59 -0000 (UTC), Veek M wrote:
> 
>> On Sat, 8 Aug 2026 01:19:32 -0000 (UTC), Lawrence D’Oliveiro wrote:
>> 
>>> b'\xef\xbf\xbf\n'.decode()
>> 
>> Could you explain how it works and what exactly is going on?
>> 
>> fh.readline() returns a unicode string with the funny chars (bytes 0xff
>> 0xff) encoded as \\xef \\xbf \\xbf - why is it \\? why not just use a
>> single u'\xef\xbf\xbf' - why is he escaping the '\'.
>> 
>> Also - how exactly is he getting ef bf bf and not ff ff?
> 
> oh is 0xff 0xff when encoded to disk in utf-8
> (sys.getsystemdefaultencoding) 0xef 0xbf 0xbf?

yes,
root@laptopveek:/tmp# od -x /tmp/x
0000000 bfef 0abf
0000004

it's the raw utf-8 encoded as bytes but since it is a unicode string why 
doesn't he save it as u'\xef\xbf\xbf' why does he escape the '\' and make 
it '\\x'
-- 
https://mail.python.org/mailman3//lists/python-list.python.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.