Read CSV File
Read a CSV file and print each row using the csv module.
BeginnerTopic: File Handling Programs
Python Read CSV File Program
This program helps you to learn the fundamental structure and syntax of Python programming.
# Program to read a CSV file
import csv
filename = input("Enter CSV filename: ")
try:
with open(filename, newline="", encoding="utf-8") as f:
reader = csv.reader(f)
for row in reader:
print(row)
except FileNotFoundError:
print("CSV file not found.")Output
Enter CSV filename: data.csv ['name', 'age'] ['Alice', '25'] ['Bob', '30']
Understanding Read CSV File
Uses csv.reader to parse comma-separated values into Python lists per row.
Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.