On Sun, 29 May 2005 at 04:42 GMT, nephish wrote: > Hey there. > i want to set a variable to represent the last line of a text file > how do i do that? > or even better, how do i create a list of the lines of a text file?
from sys import argv ## Import argv from sys module file = open(argv[1]) ## Open the file given on the command line all_lines = file.readlines() ## Read all the lines last_line = all_lines[-1] ## Assign the last line -- Chris F.A. Johnson <http://cfaj.freeshell.org> ================================================================== Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress <http://www.torfree.net/~chris/books/cfaj/ssr.html> -- http://mail.python.org/mailman/listinfo/python-list