File Handling in Python
PART – III
(Based on .csv file)
1
In the Syllabus
CSV File:
✓Import csv module
✓functions – Open / Close a .csv file
✓Read from a csv file using csv.reader ( )
✓Write into a csv file using csv.writerow( )
2
What is CSV file (Comma-Separated Values)
✓ It is most commonly used file by spreadsheet and database
applications to transfer data.
✓ It contains tabular data in plaintext. Each line represents a table
record or table row.
✓ Each record contains fields which represent data for each column in
the table. The fields are separated by commas.
3
How to create a csv file in Spreadsheet
1. Open Excel
2. Type the table data.
3. Save the file as .CSV
4. Open the file in Notepad.
5. You will find the data separated by comma.
How to create a csv file in Notepad
1. Open Notepad
2. Type the table data.
3. Save the file as .CSV
4
Read data from .csv file
5
Write data to .csv file
Read Data from the .csv file Output 6
7