formats when read and encoded to them when written unless text is always stored in files using the platform' default encodingwe need to know which encoding to useboth to load and to save to make this workpyedit uses the approaches described in detail in which we won' repeat in full here in briefthoughtkinter' text widget accepts content as either str and bytes and always returns it as str pyedit maps this interface to and from python file objects as followsinput files (opendecoding from file bytes to strings in general requires the name of an encoding type that is compatible with data in the fileand fails if the two do not agree ( decoding -bit data to asciiin some casesthe unicode type of the text file to be opened may be unknown to loadpyedit first tries to open input files in text mode to read str stringsusing an encoding obtained from variety of sources-- method argument for known type ( from headers of email attachments or source files opened by demos) user dialog replya configuration module settingand the platform default whenever prompting users for an open encodingthe dialog is prefilled with the first choice implied by the configuration fileas default and suggestion if all these encoding sources fail to decodethe file is opened in binary mode to read text as bytes without an encoding nameeffectively delegating encoding issues to the tk gui libraryin this caseany \ \ end-lines are manually converted to \ on windows so they correctly display and save later binary mode is used only as last resortto avoid relying on tk' policies and limited character set support for raw bytes text processing the tkinter text widget returns its content on request as str stringsregardless of whether str or bytes were inserted because of thatall text processing of content fetched from the gui is conducted in terms of str unicode strings here output files (savesave asencoding from strings to file bytes is generally more flexible than decoding and need not use the same encoding from which the string was decodedbut can also fail if the chosen scheme is too narrow to handle the string' content ( encoding -bit text to asciito savepyedit opens output files in text mode to perform end-line mappings and unicode encoding of str content an encoding name is again fetched from one of variety of sources--the same encoding used when the file was first opened or saved (if any) user dialog replya configuration module settingand the platform default unlike openssave dialogs that prompt for encodings are prefilled with the known encoding if there is one as suggestionotherwisethe dialog is prefilled with the next configured choice as defaultas for opens pyedita text editor program/object