Bird
0
0

Which Python code snippet correctly opens a CSV file named data.csv for reading test data?

easy📝 Syntax Q12 of 15
Selenium Python - Data-Driven Testing
Which Python code snippet correctly opens a CSV file named data.csv for reading test data?
Afile = open('data.csv', 'w')
Bfile = open('data.csv', 'r')
Cfile = open('data.csv', 'a')
Dfile = open('data.csv')
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct file mode for reading

    To read a file, use mode 'r' which stands for read-only.
  2. Step 2: Check the options

    file = open('data.csv', 'r') uses 'r' mode correctly; others use write ('w'), append ('a'), or default mode which may not be explicit.
  3. Final Answer:

    file = open('data.csv', 'r') -> Option B
  4. Quick Check:

    Read mode = 'r' [OK]
Quick Trick: Use 'r' mode to open files for reading [OK]
Common Mistakes:
  • Using 'w' which overwrites the file
  • Using 'a' which appends instead of reading
  • Not specifying mode explicitly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes