import os.path
try:
file1=input("Enter input file: ")
infile=open(filename1,"r")
file2=input("Enter output file: ")
while os.path.isfile(file2):
file2=input("File Exists! Enter new name for output file: ")
ofile=open(file2, "w")
content=infile.read()
newcontent=content.reverse()
ofile.write(newcontent)
except IOError:
print("Error")
else:
infile.close()
ofile.close()
Am I on the right track with this code? I can't seem to find a method to reverse the lines in the input file for the output file.
Input ex.
cat dog house animal
plant rose tiger tree
zebra fall winter donkey
Output ex.
zebra fall winter donkey
plant rose tiger tree
cat dog house animal