Y.G. Bae (25) [Avatar] Offline
#1
Hello.

I feel that csv.writer should have open function inside of the parenthesis as below:
>>> csv.writer(open("temp_data_03.csv", "w").writerows(temperature_data)


Thank you.

Best regards,
Y.G.
naomi.ceder (81) [Avatar] Offline
#2
Yes, another good catch!

Thanks for the report!

Naomi
Y.G. Bae (25) [Avatar] Offline
#3
I noticed that in Windows, it seems to add a carriage return, making each record ending with a ‘^M’ if I use Vim to view the file. Hence, when I csvread the file, it is getting blank “”s. Is there anyway to avoid it?
naomi.ceder (81) [Avatar] Offline
#4
[See post below on how to handle this...

Thanks for the catch... the fix is in the pipeline.]
naomi.ceder (81) [Avatar] Offline
#5
I just tried this on a Windows machine and yes, it does exactly as you describe... The csv module docs recommend avoiding this issue by always opening files for reading and writing with the newline parameter set to an empty string ('')
csv.reader(open("temp_data_03.csv", newline="")

or when writing, use:
csv.writerr(open("temp_data_03.csv", "w", newline="")


Cheers,
Naomi
Y.G. Bae (25) [Avatar] Offline
#6
Thank you, Naomi! I truly appreciate it! smilie

Best regards,
Y.G.