The operation of the file in Python uses open (filename, "w"), where filename is the file name, w refers to the write operation, it automatically overwrites all the contents of the file, as well as R read operations and a append operation.
Note that: Only one operation can be done at the same time, such as writing the time can not be read, even if you use the w+ parameter, but also just read out the blank content, but will not error, all completed an operation using the new parameters to continue different operations, such as:
f = open (filename, ' W ') #以写操作打开文件filename, the file exists then is overwritten, does not exist then establishes the F.write (' This is a test ') #执行写操作, writes the content is a testf = open (file Name) #再次以读操作打开文件filename, there is no add parameter, and the ' A ' action print f.readline () #输出读取的内容 is added by default.
This article is from the "Rickyhul" blog, make sure to keep this source http://rickyh.blog.51cto.com/10934856/1912875
Learn Python's actions on file content