How to Create CSV file in Python 3

  216 views   2 months ago Python

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.

Example

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.

Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on harsukh21@gmail.com

Related Articles