Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prepend Row to CSV file.
#1
Hello,

I am brand new to Python programming, but I have successfully manage to bodge together a script using my previous coding knowledge and some frantic Googling.

Part of the code appends a line of information to a local CSV file, and is shown below

with open('c:\power\powerdata.csv', 'a') as csvFile:
    writer = csv.writer(csvFile)
    writer.writerow(row)
csvFile.close()
I really need the line to be added at the start of the file and not at the end, as this code does. This is where I am stuck. None of my Googling has given an clean solution.

Can someone please give me a similarly elegant solution to add the row to the start of the file.

Thanks muchly!

K.
Reply


Messages In This Thread
Prepend Row to CSV file. - by KAD_UK - Sep-24-2019, 10:03 PM
RE: Prepend Row to CSV file. - by ichabod801 - Sep-24-2019, 10:24 PM
RE: Prepend Row to CSV file. - by KAD_UK - Sep-25-2019, 07:41 PM

Forum Jump:

User Panel Messages

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