in python xthere is no major distinction between text and binary files--both accept and return content as str strings the only major difference is that text files automatically map \ end-of-line characters to and from \ \ on windowswhile binary files do not ( ' stringing operations together into one-liners here just for brevity) :\codec:\python \python open('temp'' 'write('abd\ 'open('temp'' 'read('abd\nopen('temp''rb'read('abd\ \nopen('temp''wb'write('abc\ 'open('temp'' 'read('abc\nopen('temp''rb'read('abc\nwrite in text modeadds \ read in text modedrops \ read in binary modeverbatim write in binary mode \ not expanded to \ \ in python xthings are bit more complex because of the distinction between str for text data and bytes for binary data to demonstratelet' write text file and read it back in both modes in notice that we are required to provide str for writingbut reading gives us str or bytesdepending on the open modec:\codec:\python \python write and read text file open('temp'' 'write('abc\ ' open('temp'' 'read('abc\nopen('temp''rb'read( 'abc\ \ntext mode outputprovide str text mode inputreturns str binary mode inputreturns bytes notice how on windows text-mode files translate the \ end-of-line character to \ \ on outputon inputtext mode translates the \ \ back to \nbut binary-mode files do not this is the same in xand it' normally what we want--text files should for portability map end-of-line markers to and from \ (which is what is actually present in files in linuxwhere no mapping occurs)and such translations should never occur for binary data (where end-of-line bytes are irrelevantalthough you can control this behavior with extra open arguments in if desiredthe default usually works well now let' do the same againbut with binary file we provide bytes to write in this caseand we still get back str or bytesdepending on the input modewrite and read binary file open('temp''wb'write( 'abc\ ' open('temp'' 'read('abc\nopen('temp''rb'read( 'abc\nbinary mode outputprovide bytes text mode inputreturns str binary mode inputreturns bytes using text and binary files