Answers for "delete certain line from file python"


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":
Posted by: Guest on January-20-2021

python how to delete certain line number of file

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

Code answers related to "delete certain line from file python"

Python Answers by Framework

Browse Popular Code Answers by Language