insert(' 'open('udata''rb'read() pack( get(' ''end''aabac\nstring appears in gui ok it works the same if we pass str fetched in text modebut we then need to know the encoding type on the python side of the fence--reads will fail if the encoding type doesn' match the stored datat text( insert(' 'open('ldata'' 'encoding='latin- 'read() pack( get(' ''end''aabac\nt text( insert(' 'open('udata'' 'encoding='utf- 'read() pack( get(' ''end''aabac\neither waythoughthe fetched content is always unicode strso binary mode really only addresses loadswe still need to know an encoding to storewhether we write in text mode directly or write in binary mode after manual encodingc get(' ''end' 'aabac\ncontent is str open('cdata''wb'write(ctypeerrormust be bytes or buffernot str binary mode needs bytes open('cdata'' 'encoding='latin- 'write(copen('cdata''rb'read( ' \xc \xe \ \neach write returns open('cdata'' 'encoding='utf- 'write(copen('cdata''rb'read( ' \xc \ \xc \xa \ \ndifferent bytes on files open('cdata'' 'encoding='utf- 'write(copen('cdata''rb'read( '\xff\xfea\ \xc \ \ \xe \ \ \ \ \ \ open('cdata''wb'writec encode('latin- 'open('cdata''rb'read( ' \xc \xe \nmanual encoding first same but no \ on win open('cdata'' 'encoding='ascii'write(cstill must be compatible unicodeencodeerror'asciicodec can' encode character '\xc in position notice the last test herelike manual encodingfile writes can still fail if the data cannot be encoded in the target scheme because of thatprograms may need to recover from tkinter tourpart