Skip to content Skip to sidebar Skip to footer

Storing Data Into A File Rather Than Returning To The Terminal

i have this function: write_reversed_file(input_filename, output_filename) that writes to the given output file the contents of the given input file with the lines in reversed orde

Solution 1:

def write_reversed_file(input_filename, output_filename):
    s = ""
    f = open(input_filename,"r")
    lines = f.read().split("\n")
    f.close()
    for line in reversed(lines):
        s+=line.rstrip()+"\n"
    f = open(outPutFile.txt,"w")
    f.write(s)
    f.close()

Post a Comment for "Storing Data Into A File Rather Than Returning To The Terminal"