I’m new in python, I have a running code that extracts data from a web service and put it in a list and write it on a text file. When I run this code and open the text file, the data is continuous. I need something like in every line in text file, it will display 5 elements and will go to next line and write the next 5 elements and so on. Hope you can help me out on this or suggestion on other way to do this. Here’s the code.
f = open("test.txt", "w")
for item in test:
f.write("%s | " % item)
f.close()
The result looks like this:
data1, data2, data3, data4, data5, data6, data7, data8......................
It should be in this format:
data | data2 | data3 | data4 |
data5 | data6 | data7 | data8 |
data9 | data10 | data11 | data12 |
I hope I can have your inputs. Thank you!
1 Answer