Custom Search

Thursday, April 28, 2011

howto python read a file and reverse it

howto python read a file and reverse it

fp1 = open("test-1", "r")
lines = fp1.readlines()
lines.reverse()

fp2 = open("test-2", "w")
fp2.writelines(lines)

fp1.close()
fp2.close()

No comments:

Post a Comment