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 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?
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?
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: | Jacob Catayoc |
|---|---|
| Location: | Pasay City, Metro Manila, Philippines |
| Users: | 4 |
| Nodes: | 4 (0 / 4) |
| Uptime: | 497099:26:54 |
| Calls: | 182 |
| Files: | 744 |
| D/L today: |
6 files (5,132K bytes) |
| Messages: | 73,558 |