if not filereturn if not os path isfile(file)showerror('pyedit''could not open file filereturn try known encoding if passed and accurate ( emailtext none empty file 'falsetest for noneif loadencodetrytext open(file' 'encoding=loadencoderead(self knownencoding loadencode except (unicodeerrorlookuperrorioerror)lookupbad name pass try user inputprefill with next choice as default if text =none and self opensaskuserself update(else dialog doesn' appear in rare cases askuser askstring('pyedit''enter unicode encoding for open'initialvalue=(self opensencoding or sys getdefaultencoding(or '')if askusertrytext open(file' 'encoding=askuserread(self knownencoding askuser except (unicodeerrorlookuperrorioerror)pass try config file (or before ask user?if text =none and self opensencodingtrytext open(file' 'encoding=self opensencodingread(self knownencoding self opensencoding except (unicodeerrorlookuperrorioerror)pass try platform default (utf- on windowstry utf always?if text =nonetrytext open(file' 'encoding=sys getdefaultencoding()read(self knownencoding sys getdefaultencoding(except (unicodeerrorlookuperrorioerror)pass last resortuse binary bytes and rely on tk to decode if text =nonetrytext open(file'rb'read(bytes for unicode text text replace( '\ \ ' '\ 'for displaysaves self knownencoding none except ioerrorpass complete gui programs