LearnFrenzy
Sign in Take a free test

File Handling · File Handling MCQ · Question 9

Reading a huge file Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 9 Back to Exercise

What is the most memory-efficient way to process a 5 GB log file?

  • A data = f.read()
  • B lines = f.readlines()
  • C Open it in "w" mode
  • D for line in f: … (one line at a time) Correct
Correct Answer: Option D

read() and readlines() load the whole file into memory.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links