the file mode is 'rfor read'wfor writeor 'afor append these file modes assume text-mode and may implicitly perform translation of the newline character '\nfor exampleon windowswriting the character '\nactually outputs the twocharacter sequence '\ \ (and when reading the file back'\ \nis translated back into single '\ncharacterif you are working with binary dataappend 'bto the file mode such as 'rbor 'wbthis disables newline translation and should be included if you are concerned about portability of code that processes binary data (on unixit is common mistake to omit the 'bbecause there is no distinction between text and binary filesalsobecause of the distinction in modesyou might see text-mode specified as 'rt''wt'or 'at'which more clearly expresses your intent file can be opened for in-place updates by supplying plus (+charactersuch as ' +or ' +when file is opened for updateyou can perform both input and outputas long as all output operations flush their data before any subsequent input operations if file is opened using ' +modeits length is first truncated to zero if file is opened with mode 'uor 'ru'it provides universal newline support for reading this feature simplifies cross-platform work by translating different newline encodings (such as '\ ''\ 'and '\ \ 'to standard '\ncharacter in the strings returned by various file / functions this can be useful iffor exampleyou are writing scripts on unix systems that must process text files generated by programs on windows the optional bufsize parameter controls the buffering behavior of the filewhere is unbuffered is line bufferedand negative number requests the system default any other positive number indicates the approximate buffer size in bytes that will be used python adds four additional parameters to the open(functionwhich is called as open(name [,mode [,bufsize [encoding [errors [newline [closefd]]]]]]encoding is an encoding name such as 'utf- or 'asciierrors is the error-handling policy to use for encoding errors (see the later sections in this on unicode for more informationnewline controls the behavior of universal newline mode and is set to none'''\ ''\ 'or '\ \nif set to noneany line ending of the form '\ ''\ 'or '\ \nis translated into '\nif set to '(the empty string)any of these line endings are recognized as newlinesbut left untranslated in the input text if newline has any other legal valuethat value is what is used to terminate lines closefd controls whether the underlying file descriptor is actually closed when the close(method is invoked by defaultthis is set to true table shows the methods supported by file objects table file methods method description read([ ] readline([ ]reads at most bytes reads single line of input up to characters if is omittedthis method reads the entire line reads all the lines and returns list size optionally specifies the approximate number of characters to read on the file before stopping writes string writes all strings in sequence lines closes the file readlines([size] write(sf writelines(linesf close( lib fl ff