mhysnm1...@gmail.com wrote:

> Now I am
> trying to export to a CSV file. There is no syntax or logical errors I can
> see. The information is being exported to the CSV. But when I bring it
> into Excel. I am getting a blank row between each row.

> with open ('books-list.csv', 'w') as wf:

Try switching off newline conversion:

with open('books-list.csv', 'w', newline="") as wf:
   ...

The csv.writer() delimits records with "\r\n", and on Windows open() 
converts "\n" to "\r\n" by default. Therefore you probably (no Window handy 
to to confirm) end up with "\r\r\n" between the rows.

See also <https://docs.python.org/dev/library/csv.html#id3>.

>     writer = csv.writer(wf)
>     writer.writerows(books)

At this point the file is already closed by the context manager, no need for 
an extra

> wf.close()


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to