samedi 31 octobre 2015

writing a new text file in python

I am writing a code that go over text file and counting how many eords are in every line. Im having trouble puting the result (many lines that each consist a number) into a new text.file i wrote it like that:

 in_file = open("our_input.txt")
 out_file =open("output.txt", "w")


for line in in_file:
line= (str(line)).split()
x=(len(line))
x=str(x)
out_file.write(x)

in_file.close()  
out_file.close()

but the file im getting has all the number together in one line. how do i seperate them in the file im making?

Aucun commentaire:

Enregistrer un commentaire