Answers for "python how to delete certain line number of file"

0

python how to delete certain line number of file

#!/usr/bin/python
def deleteLine():
 fn = 'myfile'
 f = open(fn)
 output = []
 str="The string i wish to delete
 for line in f:
   if not line.startswith(str):
    output.append(line)
 f.close()
 f = open(fn, 'w')
 f.writelines(output)
 f.close()
deleteLine()
Posted by: Guest on May-20-2021

Code answers related to "python how to delete certain line number of file"

Python Answers by Framework

Browse Popular Code Answers by Language