Home > other >  How to read the file in every line of the first number
How to read the file in every line of the first number

Time:11-27

I have a dat file, want to read the file in each row of the first data, how to make this program in Python?

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)
  • Related