Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Delete final line in file with python

$
0
0

How can one delete the very last line of a file with python?

Input File example:

helloworldfoobar

Output File example:

helloworldfoo

I've created the following code to find the number of lines in the file - but I do not know how to delete the specific line number.

    try:        file = open("file")    except IOError:        print "Failed to read file."    countLines = len(file.readlines())

Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>