Enrol to start learning
Reading is open to everyone. Enrolling is free, and it is what unlocks the audio lessons, practice tests and progress tracking.
13.2.2. File Modes
This section
Practice test
12 questions on this section. Wrong answers show you what to read again.
Sign up to take itWhole chapter
Revision test
Mixed questions from across the chapter. Your answers get marked.
Sign up to take itQuick
Flashcard drill
4 cards from this lesson. Good the night before a test.
Try these first
- 1.
What does the 'r' mode allow you to do with a file?
Hint
Think about access rights.
- 2.
What happens when you open a file in 'w' mode?
Hint
What does 'w' stand for?
- 3.
What mode would you use to read a file without modifying it?
- r
- w
- a
Hint
Think about what you can do without changing the file.
- 4.
True or False: The 'w' mode will preserve the file content if it already exists.
- True
- False
Hint
What happens to the old data?
- 5.
You have a file that logs errors in your application. Write a Python function that opens this file in 'a' mode to add new error log entries. Explain how you ensure that existing entries remain intact.
Hint
Think about how you can open the file so everything stays there.
- 6.
Design a program that reads data from a binary file using 'rb' mode. Explain what will happen if you unintentionally open the file in 'r' mode instead.
Hint
Consider the type of data you're dealing with.
Exercises
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
4 more questions available
Enrol freeQuiz
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
2 more questions available
Enrol freeChallenge Problems
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting