I'm trying to append data to a CSV file. I'd like to be able to make manual changes to the file from time to time in Excel MacOS then rerun the python program.
However, when I open the file and save it in Excel MacOS, it removes a hard return. Then on subsequent runs the lack of a hard return messes up the formatting.
with open("test.csv", 'a', newline='', encoding='utf-8') as csvfile:
fieldnames = ['ID', 'Name']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writerow({'ID': "1", 'Name': "Frank"})
writer.writerow({'ID': "2", 'Name': "Bob"})
After initial python run
$ cat -e test.csv
1,Frank^M$
2,Bob^M$
After manual save in Excel on MacOS
$ cat -e test.csv
1,Frank^M$
2,Bob
After running python program a second time. Notice the messed up formatting.
$ cat -e test.csv
1,Frank^M$
2,Bob1,Frank^M$
2,Bob^M$