Back to all Computer Science topics
Topic 6.5Computer Science SL5 flashcards

File processing

Practice Flashcards

Flip cards to reveal answers
Card 1 of 56.5.1
6.5.1
Question

What are the three file modes and what does each do?

Click to reveal answer

Track your progress — Sign up free to save your progress and get smart review reminders based on spaced repetition.

All Flashcards in Topic 6.5

Below are all 5 flashcards for this topic. Sign up free to track your progress and get personalized review schedules.

6.5.15 cards

Card 1definition
Question

What are the three file modes and what does each do?

Answer

r reads and fails if the file does not exist. w empties the file immediately and then writes, creating it if absent. a appends at the end, keeping what was already there.

Card 2concept
Question

What is the danger of opening a file in w mode?

Answer

It empties the file the moment it opens, before anything is written. Choosing w when you meant a destroys the previous contents, and no error is raised because it is a valid operation.

Card 3process
Question

Why must a line read from a file be stripped and converted?

Answer

Every line carries the invisible newline that ended it, so comparisons fail until it is stripped. And everything read is text, so "72" must be converted with int() before any arithmetic.

Card 4concept
Question

Why must a file be closed?

Answer

Its contents may not be fully written to disk otherwise, and an open file holds a system resource, possibly locking it against other programs.

Card 5definition
Question

What does a with block do for file handling?

Answer

It closes the file automatically when the block ends, even if something fails inside it. It is the finally block of exception handling, built into the language.

Want smart review reminders?

Sign up free to track your progress. Our spaced repetition algorithm will tell you exactly which cards to review and when.

Start Free
IB Computer Science SL Topic 6.5 Flashcards | File processing | Aimnova