| Mode |
Description |
| R |
Read-only |
| r+ |
Write |
| W |
Write, delete the original file before re-writing, if the file is not created |
| w+ |
Read and write, first delete the original file, re-write, if the file is not created (can write output) |
| Mode |
Description |
| A |
Writes, appends new content to the end of the file, and the file does not exist, creates |
| A + |
Read-write, append new content to the end of file, file does not exist, create |
| B |
Open the binary file. Can be used in conjunction with r,w,a,+ |
| U |
All line break symbols are supported. "\ r", "\ n", "\ r \ n" |
|
|
|
|
|
|
File Object methods:
string=fileobject.readline ()#只读取一行内容
list=fileobject.readlines ()#读取文件里面所有的内容, put the contents of each line in the file into a list
string=fileobject.read ()#读取全部内容
Fileobject.write (String)
Fileobject.writelines (list)
Fileobject.close ()
Fileobject.next ()
Fileobject.seek (offset, option (0 first, 1 current position, 2 tail))
Filebject.flush () #更新文件内容
Filebject.tell ()#查看当前文件指针的位置
Filebject. truncate ()#清空文件内容
Python file read/write