Python 3 easy way to read and write files!
A = open (' Test.txt ', ' W ')
This line of code creates a text document named Test, the pattern is write (the pattern is divided into three types, W stands for writing, R is for reading, and a for the tail line is added).
A.write (' hello,world! ')
This line of code is to write data to the Test.txt file, which is written in the ' hello,world! ’。 The data you write is what you see when you open the file.
A.close ()
Remember to close the file when you are finished reading and writing.
Print (A.readline ())
Displays the contents of the first line in the file, executes multiple times, and then displays the second row, the third line ...
A.seek (0)
Go back to the beginning of the file, and if you use the ReadLine method, the position will go to the third row or other location (see which line you are performing), and use Seek () to return to the beginning of the document.
Print (A.read (12))
Displays the contents of the first 12 sizes of a document.
This is the simple Python 3 in the new file, read the file, modify the file method.
Python 3 easy way to read and write files!