0

I have a file that prints line by line if match is in line, and if the string "Expected" is in line. However, I want the line to start with match instead of the actual beginning of the line.

This is the code I have

F = open(path,'r')
writestring = ''
for line in F:
    if match in line:
        if 'Expected' in line:
            writestring = writestring+line+'\n'
dimay
  • 2,768
  • 1
  • 13
  • 22

1 Answers1

1

To print line starting from the point where match occurs, you can do this:

print(line[line.index(match):])

line.index(match) returns the index where match occurs in line, and line[line.index(match):] is the substring from that index to the end of the string.

khelwood
  • 55,782
  • 14
  • 81
  • 108