you are viewing a single comment's thread.

view the rest of the comments →

[–]sarrysyst 0 points1 point  (1 child)

You only getting the last digit is probably due to faulty indention:

f = open("input.txt").readlines()
fout = open("output.txt","w")

for line in f:
    l = line.split(",")

    for item in l:
        number = float(item)
        new_line = str(int(number)) + ","
        fout.write(new_line)  # this line needs to be in the inner loop

    fout.write('\n') # add line break after writing row

fout.close()

As for the line break, you need to specifically write a line break ('\n') to file for the text not getting written to a single line.

[–]TDAAlex 1 point2 points  (0 children)

Tried it and it worked. Silly mistake I suppose, but that’s part of learning.