Jul-21-2018, 02:09 PM
Try to use the context manage
Check if this is what you want:
with
when manipulate files.Check if this is what you want:
with open("a.txt", "r") as f_in: with open("out.txt", "w+") as f_out: for line in f_in: words = line.split(' ')[:10] f_out.write(' '.join(words) + '\n')