Read in every line that starts with a certain character from a file

后端 未结 3 2039
一个人的身影
一个人的身影 2021-01-19 12:19

I am trying to read in every line in a file that starts with an \'X:\'. I don\'t want to read the \'X:\' itself just the rest of the line that follows.

with o         


        
3条回答
  •  灰色年华
    2021-01-19 12:47

    Read every line in the file (for loop)
    Select lines that contains X:
    Slice the line with index 0: with starting char's/string as X: = ln[0:]
    Print lines that begins with X:

    for ln in input_file:
        if  ln.startswith('X:'):
            X_ln = ln[0:]
            print (X_ln)
    

提交回复
热议问题