Save the previous line in a variable if you want the previous line only. for line in inp: # Perform some operations with line if condition something: print prev_line print line break # I need to go back one line and use that line value --> prev_line = line
If you want to do more than that, then use data=inp.readlines() or you can use data = open(myfile), "r").readlines(). The data will be stored in list format so you can access each line individually. -- http://mail.python.org/mailman/listinfo/python-list