Python read the file, in the use of Readlin, ReadLines will have doubts, the following for you to explain:
Example: The content of A.txt is
AAA 123
BBB 456
Second, first I set a variable:
A= "A.txt"
C=file (a)
Thirdly, we look at the reading results using read, ReadLine, ReadLines, respectively:
(1), read:
In:c.read ()
Out: '
So:read each time a file is read, it is usually put into a string variable, that is, the content of the. Read () generated file is a string type.
(2), ReadLine:
In:c.readline ()
Out: ' AAA 123\n '
So:readline each read a single line of the file, usually a line of text that is read into a string variable, and the type of STR is returned.
(3), ReadLines:
In:c.readlines ()
Out: [' AAA 123\n ', ' BBB 456\n ']
So:readlines reads the entire contents of the file per row, places the read into a list, and returns the list type.
This article from the "11421725" blog, reproduced please contact the author!
Python:file (Read,readline,readline) How to use