How can one delete the very last line of a file via python?
file = open("file")
print "Failed to read file."
countLines = len(file.readlines())
import os, sys
readFile = open("file")
lines = readFile.readlines()
w = open("file",'w')
w.writelines([item for item in lines[:-1]])
You could use the above code and then:-
lines = file.readlines() lines = lines[:-1]
This would give you an array of lines containing all lines but the last one.