Home Python How to create csv file in Python?

How to create csv file in Python?

by therichpost
How to create csv file in Python?

Hello friends, welcome back to my blog. Today this blog post I will tell you, How to create csv file in Python?.

Guy’s if you are new in Python then please check below link for more Python tutorials:

  1. Python Tutorials

Guy’s here is the working code snippet for How to create csv file in Python? and please use it carefully:

1. Guys here is the working code snippet:

import csv
import ast
i = [['a', 'b'], 'c', 'd']
with open('a.csv', 'a', newline='', encoding='utf-8') as file:
    writer = csv.writer(file, delimiter=';')
    writer.writerow(i)

file.close()
with open('a.csv', 'r', newline='', encoding='utf-8') as file:
    for i in csv.reader(file, delimiter=';'):
        i[0] = ast.literal_eval(i[0])
        print(type(i),type(i[0]), i[0][0])

This is it guy’s. Guy’s if you have any kind of query then please comment below. Guy’s I will come with more demos soon.

I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad because with your views, I will make my next posts more good and helpful.

Jassa

Thanks

Related Articles

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.