How to Create CSV file in Python 3


In this article, I will share with you how to create or generate a CSV file in python3 with an example. as you know if you work in python application then you should use many time or you need to create a CSV file in python application.

Python provides many helpful libraries for developer help of those libraries you can doing and implement your functionality very easily in your python application.

Python also provides a CSV library for doing all the tasks and make functionality for CSV related files. With the help of the CSV library, you can create CSV files from data, you can read CSV file and store data in the database, you can make formated CSV structure and much more.

In this article, we also create simple CSV file help of python's CSV library and create one simple CSV file with the static data. but, in your application, you can easily implement dynamic logic and then created a CSV file from the database data.

Python has already by default install CSV library.


import csv

with open('/path_of_folder/innovators.csv', 'w', newline='') as file:
    writer = csv.writer(file)
    writer.writerow(["SN", "Name", "Contribution"])
    writer.writerow([1, "Linus Torvalds", "Linux Kernel"])
    writer.writerow([2, "Tim Berners-Lee", "World Wide Web"])
    writer.writerow([3, "Guido van Rossum", "Python Programming"])

i hope you like this article.