I am learning python at the moment and I have a text file with lots of numbers separated by a newline (\n) like:
5
100
7
83
What’s the easiest way to read/write into a new text file putting the numbers into a comma delimited format like:
5, 100, 7, 83
For each line in the file, you want to split it apart on spaces and rejoin it with commas:
You could also look at the csv module, if you want to do anything more complicated.