Deleting A Line From A Text File
How to you delete a specific line from a text file using readlines() like: f_open = open('textfile.txt', 'r') lines = f_open.readlines() How do you use lines to choose a line in t
Solution 1:
Use the fileinput module's inplace functionality. Refer Optional in-place filtering section at fileinput. The example below deletes the first line from a file:
import fileinput
import sys
for line_number, line in enumerate(fileinput.input('myFile', inplace=1)):
ifline_number== 0:
continueelse:
sys.stdout.write(line)
Post a Comment for "Deleting A Line From A Text File"