Python Forum
In CSV, how to write the header after writing the body?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
In CSV, how to write the header after writing the body?
#1
Hello Forum,

I'm using csv package to build a .csv file in Python v3.6.
What I'm doing is converting and combining several .bib files into one CSV, which like reading text files and then putting them all in one CSV format. The nature of the files that I'm dealing with does not allow me to know the full header of the CSV in advance. Each file might add one or more header item. Which means that as I'm reading the files, the header keeps updating.

The code that I wrote is using csv.writer.writerow() to build the "Body" of the CSV first. After the CSV body is completely built, I want to go back and write the header.

So the question is, after using csv.writer.writerow(), how to go back to the top of the CSV file and add new first row (the header)?

Thank you all,
Reply


Messages In This Thread
In CSV, how to write the header after writing the body? - by Tim - Jan-02-2018, 10:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [BeautifulSoup] Find </body>? Winfried 3 1,442 Jul-21-2023, 11:25 AM
Last Post: Gaurav_Kumar
  Get html body of URL rama27 6 3,569 Aug-03-2020, 02:37 PM
Last Post: snippsat
  malformed header from script 'main.py': Bad header: * Serving Flask app "main" anuragsapanbharat 2 4,596 Jun-12-2019, 07:26 AM
Last Post: anuragsapanbharat
  Is it possible to perform a PUT request by passing a req body instead of an ID ary 0 1,867 Feb-20-2019, 05:55 AM
Last Post: ary

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020