Bird
0
0

What is wrong with this code snippet for logging data to CSV on Raspberry Pi?

medium📝 Troubleshoot Q7 of 15
Raspberry Pi - Data Logging and Databases
What is wrong with this code snippet for logging data to CSV on Raspberry Pi?
import csv
with open('log.csv', 'a') as file:
    writer = csv.writer(file)
    writer.writerow('12:00', '24')
AMissing file.close() call
Bwriter.writerow expects a single iterable argument, not multiple arguments
Ccsv.writer cannot write strings
DFile should be opened in 'w' mode, not 'a'
Step-by-Step Solution
Solution:
  1. Step 1: Check writer.writerow usage

    writer.writerow requires one iterable argument like a list or tuple, not multiple separate arguments.
  2. Step 2: Analyze code error

    Passing two separate strings causes a TypeError.
  3. Final Answer:

    writer.writerow expects a single iterable argument, not multiple arguments -> Option B
  4. Quick Check:

    Pass list or tuple to writer.writerow [OK]
Quick Trick: Pass a list or tuple to writer.writerow, not separate arguments [OK]
Common Mistakes:
MISTAKES
  • Passing multiple arguments instead of one iterable
  • Confusing file modes
  • Forgetting to close file (with handles this is safe)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes