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)
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)
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()
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us