Answers for "file remove line 1 python"

0

python read and delete line from file

with open("yourfile.txt", "r") as f:
    lines = f.readlines()
with open("yourfile.txt", "w") as f:
    for line in lines:
        if line.strip("n") != "nickname_to_delete":
            f.write(line)
Posted by: Guest on January-20-2021
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

Python Answers by Framework

Browse Popular Code Answers by Language