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 ?
b'\xef\xbf\xbf\n'.decode()
On Sat, 8 Aug 2026 01:19:32 -0000 (UTC), Lawrence DrCOOliveiro 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?
On Sat, 8 Aug 2026 04:22:59 -0000 (UTC), Veek M wrote:
On Sat, 8 Aug 2026 01:19:32 -0000 (UTC), Lawrence DrCOOliveiro 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?
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'
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 74 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 53:34:37 |
| Calls: | 1,101 |
| Calls today: | 1 |
| Files: | 1,339 |
| Messages: | 276,196 |