Python file reading and writing is determined by the parameters of the open () function to read and write
Open (file, mode= ' R ', Buffering=none, Encoding=none, Errors=none, Newline=none, Closefd=true)
The Open function defaults to r mode as read-only mode, the Open function is shared with R r+ W w+ A + six modes, the following is the explanation of 6 modes
Functions for reading and writing files
F=open ('Book.txt', encoding='Utf-8') F.read ()#the method reads in from the beginning of the file, and if it does not pass in count, it tries to read as much more content as possible, most likely until the end of the file. F.readline ()#read a row of a fileF.readlines (Sizeint)#reads all the rows and returns the list, and, given sizeint>0, sets how many bytes are read at a time, in order to alleviate the read pressure. F.write ()#writes a string to the file, returning the length of the written character. F.writelines ()#writes a list of sequence strings to the file and adds a newline character to each line if a line break is required. F.seek ()#set the current location of the fileF.tell ()#returns the current location of the fileF.truncate (f)#Empty FileF.flush ()#writes the contents of a buffer to a fileF.close ()#Close File
Python file read/write