[Solved] How to delete text form txt file using python


You could do it like this:

input_file = open('filename.txt')
output_file = open('output_filename.txt', 'w')
for line in input_file.readlines()[1:]:
    output_file.write(line + '\n')
output_file.close()

Same thing using single file:

input_file = open('filename.txt')
input_data = [line for line in input_file.readlines()]
input_file.close()

output_file = open('filename.txt', 'w')
for line in input_data[1:]:
    output_file.write(line + '\n')
output_file.close()

2

solved How to delete text form txt file using python