CodePudding user response:
Can use the file. Readlines (to read the number of rows), then make a judgment whether the current line, if there is no break, if there is a can use the string of the split () method for cutting, the first group of pick up after cutting data [0], can,CodePudding user response:
With the open (r 'file path/filename. TXT', 'r', encoding="utf-8") as f:
For li in f.r eadlines () :
Print (li [0])
CodePudding user response:
Then the program here if you want to read a few lines specified data how to change?CodePudding user response:
import linecache as lc
The content=lc. Getline (filename, line number)