Bird
0
0

What is wrong with this code snippet for reading CSV data?

medium📝 Debug Q7 of 15
Selenium Python - Data-Driven Testing
What is wrong with this code snippet for reading CSV data?
import csv
with open('data.csv', 'r') as file:
    reader = csv.reader(file)
    for row in reader:
        print(row[3])
AMissing delimiter argument in csv.reader
Bcsv.reader does not support indexing
CFile not opened in binary mode
DIndexError if row has fewer than 4 columns
Step-by-Step Solution
Solution:
  1. Step 1: Understand list indexing in csv.reader rows

    Each row is a list; accessing index 3 means 4th column.
  2. Step 2: Identify risk of IndexError

    If any row has fewer than 4 columns, accessing row[3] causes IndexError.
  3. Final Answer:

    IndexError if row has fewer than 4 columns -> Option D
  4. Quick Check:

    Accessing missing index = IndexError = A [OK]
Quick Trick: Check row length before indexing [OK]
Common Mistakes:
  • Assuming all rows have enough columns
  • Thinking csv.reader rows are dicts
  • Believing binary mode is needed for CSV

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes