1: 2: 3: 4: 5: 6:
filename = 'thefile.txt' lines = file(filename).readlines() new_lines = ['one more line at the top\n'] + lines f = open(filename,'w') f.writelines(new_lines) f.close()