Bird
0
0

What is the main issue with this CSV reading code?

medium📝 Debug Q6 of 15
Selenium Python - Data-Driven Testing
What is the main issue with this CSV reading code?
import csv
file = open('data.csv')
reader = csv.reader(file)
for row in reader:
print(row)
Acsv.reader cannot read files opened without 'with'
BThe file is opened in write mode instead of read mode
CThe print statement is not indented inside the for loop
DThe file is not closed after reading
Step-by-Step Solution
Solution:
  1. Step 1: Check indentation

    Python requires the print inside the loop to be indented.
  2. Step 2: File mode and closing

    File defaults to read mode; not using 'with' is not an error but less safe.
  3. Final Answer:

    The print statement is not indented inside the for loop -> Option C
  4. Quick Check:

    Indent loop body correctly to avoid syntax errors [OK]
Quick Trick: Indent loop contents properly [OK]
Common Mistakes:
  • Ignoring Python indentation rules
  • Assuming file mode defaults to write
  • Believing csv.reader requires 'with' statement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes