Menu

Writing to CSV file is appending instead of overwriting

Reddit r/learnpython·u/Hippopotamosssss·7 months ago
#mKeI7L26
#fiction#nonfiction#book#file#appending
Reading 0:00
15s threshold

*SOLVED* Had to read the file, make the changes, then write it. Thanks everyone!

So I'm trying to write a randomizer for books using two csv files (one for fiction and one for nonfiction) and I want the line with the chosen book to be erased from the csv file but I have not been able to make that work.

The code below is what I have right now and what it's doing is appending the file with the altered entries (with the chosen book removed) so that there's the original full list followed by the altered list. How do I get it to overwrite the file instead of appending it?

delete = input("Do you want to delete this book from the list?…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.