KwickClips Python · 45 sec · free
Why did my old lines vanish?
Short answer. You opened the file with mode w, which erases it first.
Which mode adds without erasing?
Mode a.
Six file modes
| Mode | Does | If missing |
|---|---|---|
| r | reads | error |
| w | erases, writes | creates it |
| a | adds at end | creates it |
| r+ w+ a+ | read + write | like r, w, a |
Remember
| w erases old text |
| a keeps it and adds |
You opened a file to add a line, and old lines vanished. Why? You used the mode w. Mode r only reads. Mode w erases first. Mode a adds at the end. A plus adds reading and writing. Mode w erases old text. Mode a keeps it and adds.
This clip is from the full lesson: Text File Handling: Open, Read, Write and Append — 9 minutes, with the tables, the quick answers and the whole lesson in text.
Useful for: CBSE Class 12 Computer Science (083), CBSE Class 12 Computer Science (083), CBSE Class 12 Computer Science (083), Cambridge IGCSE Grade 9 Computer Science (0478)
More KwickClips from this lesson
Why do variables lose data?40 sec
What does readlines() return?39 sec
What happens when the with block ends?39 sec
What does tell() return?42 secVoice-over is AI-generated; the script is written and checked by Kajal Ma'am. Confirm anything you plan around against your official board document. We never ask for a password or an OTP.

