Hang on python file read and write r + mode

Write when the script needs to be a line to modify the file, my changes logic, open the file with r + mode, then the original file data is read into an array, the corresponding element to modify the array in the seek (0), then the array write into the file

result:

Files are always one extra line at the end of 'D \ n', I am also its strange, studied for a long time scratching, still found problems, and can, for example, open the file in other ways with r, and then writes a new file (open with w way) there is no problem

In the end I did not find out what the problem is, but caved in, read by r way, the new file is written,

 

Conclusion: The file r + read mode with caution

 

Expectations: will one day be able to know why

Guess you like

Origin www.cnblogs.com/mghhzAnne/p/10949749.html
Recommended