When using the csv module to read a file, which object allows you to access…

2026

When using the csv module to read a file, which object allows you to access each row of the CSV file as a dictionary, where the keys are the column headers?

  1. A.

    csv.reader()

  2. B.

    csv.DictReader()

  3. C.

    csv.writer()

  4. D.

    csv.ListReader()

Attempted by 118 students.

Show answer & explanation

Correct answer: B

To access each row of a CSV file as a dictionary where keys are column headers, use the csv.DictReader() class. While csv.reader() returns rows as lists of strings, csv.DictReader() maps the first row to keys and subsequent rows to dictionaries based on those headers.

Explore the full course: Rssb Senior Computer Instructor