python how to delete certain line number of file

Solutions on MaxInterview for python how to delete certain line number of file by the best coders in the world

showing results for - "python how to delete certain line number of file"
Javier
06 Jul 2020
1#!/usr/bin/python
2def deleteLine():
3 fn = 'myfile'
4 f = open(fn)
5 output = []
6 str="The string i wish to delete
7 for line in f:
8   if not line.startswith(str):
9    output.append(line)
10 f.close()
11 f = open(fn, 'w')
12 f.writelines(output)
13 f.close()
14deleteLine()
15