read from source file one line at a time and write to target file one line at time.
def copy(src_file, target_file): with open(src_file) as fin: with open(target_file, 'w') as fout: while True: line = fin.readline() if not line: break fout.write(line) copy('source.txt', 'target.txt')