MAC python 2.7 series
I wanted to write a new line to a locally existing csv file. For some reason this didn't work, so I'll summarize it.
import csv
c = csv.writer(open(path, 'w'))
lst = ['a','b','c','d']
lst.append('\n')
c.writerow(lst)
Looking at the Japanese source site, it seems to work fine. There were times when it worked and times when I tried it, but in most cases it was out!
import csv
c = csv.writer(open(path, 'a'))
lst = ['a','b','c','d']
lst.append('\n')
c.writerow(lst)
I changed the mode of open () to `'w'->'a'`
.
It seems that'a' is fine because I just wanted to write to an existing file.
There was a detailed description in site here.
If only the write process is performed without performing the read process at all, the data will be overwritten from the beginning of the file (as it is), but if the written length is shorter than the original data, the written data will end. The original data remains behind.
I see ~
The delivery date was not in time. The reason I didn't make it in time was that the execution time was long, so I fell asleep with the script running.
When I woke up in the morning, there was only one line in the csv file, so I screamed and went to bed again.
Recommended Posts