' python / bin(function in additionbinary files do not perform any end-of-line translation on datatext files by default map all forms to and from \ when written and read and implement unicode encodings on transfers in binary files like this one work the same in python xbut byte strings are simply normal strings and have no leading when displayedand text files must use the codecs module to add unicode processing per the note at the start of this thoughthat' as much as we're going to say about unicode text and binary data files hereand just enough to understand upcoming examples in this since the distinction is of marginal interest to many python programmerswe'll defer to the files preview in for quick tour and postpone the full story until for nowlet' move on to some more substantial file examples to demonstrate few common use cases storing python objects in filesconversions our next example writes variety of python objects into text file on multiple lines notice that it must convert objects to strings using conversion tools againfile data is always strings in our scriptsand write methods do not do any automatic to-string formatting for us (for spacei' omitting byte-count return values from write methods from here on)xyz 'spamd {' ' ' ' [ open('datafile txt'' ' write( '\ ' write('% ,% ,% \ (xyz) write(str( '$str( '\ ' close(native python objects must be strings to store in file create output text file terminate lines with \ convert numbers to strings convert and separate with once we have created our filewe can inspect its contents by opening it and reading it into string (strung together as single operation herenotice that the interactive echo gives the exact byte contentswhile the print operation interprets embedded endof-line characters to render more user-friendly displaychars open('datafile txt'read(raw string display chars "spam\ , , \ [ ]${' ' ' ' }\nprint(charsuser-friendly display spam , , [ ]${' ' ' ' we now have to use other conversion tools to translate from the strings in the text file to real python objects as python never converts strings to numbers (or other types of tuplesfilesand everything else