objectstext-mode files interpret file contents according to unicode encoding--either the default for your platformor one whose name you pass in by passing in an encoding name to openyou can force conversions for various types of unicode files textmode files also perform universal line-end translationsby defaultall line-end forms map to the single '\ncharacter in your scriptregardless of the platform on which you run it as described earliertext files also handle reading and writing the byte order mark (bomstored at the start-of-file in some unicode encoding schemes binary-mode files instead return file content to you rawas sequence of integers representing byte valueswith no encoding or decoding and no line-end translations the second argument to open determines whether you want text or binary processingjust as it does in python--adding to this string implies binary mode ( "rbto read binary data filesthe default mode is "rt"this is the same as " "which means text input (just as in xin xthoughthis mode argument to open also implies an object type for file content representationregardless of the underlying platform--text files return str for reads and expect one for writesbut binary files return bytes for reads and expect one (or bytearrayfor writes text file basics to demonstratelet' begin with basic file / as long as you're processing basic text files ( asciiand don' care about circumventing the platform-default encoding of stringsfiles in look and feel much as they do in (for that matterso do strings in generalthe followingfor instancewrites one line of text to file and reads it back in xexactly as it would in (note that file is no longer built-in name in xso it' perfectly ok to use it as variable here) :\codec:\python \python basic text files (and stringswork the same as in file open('temp'' 'size file write('abc\ 'file close(file open('temp'text file read(text 'abc\nprint(textabc unicode and byte strings returns number of characters written manual close to flush output buffer default mode is " (="rt")text input