Sujet : Re: Decoding bytes to text strings in Python 2
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.pythonDate : 21. Jun 2024, 19:43:13
Autres entêtes
Organisation : Stefan Ram
Message-ID : <Text-20240621184010@ram.dialup.fu-berlin.de>
References : 1
Rayner Lucas <
usenet202101@magic-cookie.co.ukNOSPAMPLEASE> wrote or quoted:
What's Python 2 doing here? sys.getdefaultencoding() returns 'ascii',
but it's clearly not attempting to display the bytes as ASCII (or
cp1252, or ISO-8859-1). How is it deciding on some sort of almost-but-
not-quite UTF-8 decoding?
I didn't really do a super thorough deep dive on this,
but I'm just giving the initial impression without
actually being familiar with Tkinter under Python 2,
so I might be wrong!
The Text widget typically expects text in Tcl encoding,
which is usually UTF-8.
This is independent of the result returned by sys.get-
defaultencoding()!
If a UTF-8 string is inserted directly as a bytes object,
its code points will be displayed correctly by the Text
widget as long as they are in the BMP (Basic Multilingual
Plane), as you already found out yourself.