To append content to an existing CSV file in Python, we can make use of the built-in csv
module. The steps involved are:
writerow()
method.main.py278 chars14 lines
In the above example, we open a file named "filename.csv" in append mode using the with
statement, which automatically closes the file when we're done with it. We then create a CSV writer object and pass it the file. Finally, we use the writerow() method to write the data to the CSV file.
Note that we need to pass the data as a list to the writerow() method. In this example, we are adding three values: "John", "Doe", and "30".
gistlibby LogSnag