Bird
0
0

Which Python statement correctly opens a CSV file named input.csv for reading test data?

easy📝 Conceptual Q3 of 15
Selenium Python - Data-Driven Testing
Which Python statement correctly opens a CSV file named input.csv for reading test data?
Awith open('input.csv', 'r') as file:
Bopen('input.csv', 'w')
Cfile = open('input.csv', 'a')
Dwith open('input.csv', 'x') as file:
Step-by-Step Solution
Solution:
  1. Step 1: Identify file mode for reading

    To read a file, mode should be 'r'.
  2. Step 2: Use context manager

    Using 'with' ensures proper file closing.
  3. Final Answer:

    with open('input.csv', 'r') as file: -> Option A
  4. Quick Check:

    Use 'r' mode and 'with' for safe reading [OK]
Quick Trick: Use 'r' mode with 'with' to read files safely [OK]
Common Mistakes:
  • Using 'w' or 'a' modes which are for writing/appending
  • Not using 'with' leading to unclosed files
  • Using 'x' which is for exclusive creation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes