#------------------------------------------------------------------------------ # File2.py #------------------------------------------------------------------------------ # main() ---------------------------------------------------------------------- def main(): # read all lines into a list f = open('Matrix.py') # default mode is 'r' L = f.readlines() f.close() # print the list print() print(L) print() # L.sort() # print to a back-up file g = open('Matrix.py.bak', 'w') for line in L: g.write(line) # note that write() does not insert a newline # end for g.close() # another way to print to a file g = open('Matrix.py-2.bak', 'w') # re-use the file variable g for line in L: print(line, end='', file=g) # print() does insert a newline, supress it # end for g.close() # end main() ------------------------------------------------------------------ # ----------------------------------------------------------------------------- if __name__=='__main__': main() # end if ----------------------------------------------------------------------