176. CSV Parsing with DictReader
import csv
# Example CSV content
csv_data = """name,age,city
Alice,30,New York
Bob,25,Los Angeles
Charlie,35,Chicago"""
# Writing the CSV content to a file
with open('people.csv', 'w', newline='') as file:
file.write(csv_data)
# Reading the CSV file with DictReader
with open('people.csv', mode='r') as file:
reader = csv.DictReader(file)
for row in reader:
print(dict(row))Last updated