Welcome folks today in this blog post we will be creating the csv
file using csv
module in command line using python. All the full source code of the application is shown below.
Get Started
In order to get started you need to make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 |
import csv writer = csv.writer(open("out.csv", 'w')) writer.writerow(['name', 'address', 'phone', 'etc']) writer.writerow(['bob', '2 main st', '703', 'yada']) writer.writerow(['mary', '3 main st', '704', 'yada']) |
As you can see we are importing the built in csv
module and then we are using the writer()
method to open the new output
file called out.csv
and we are opening the file inside the write
mode. And then we are writing the rows inside the csv
file using the writerow()
method.