Python File Handling
Python File Handling
1. Open a File
This creates a file and writes inside it. "w" = write mode (creates/overwrites)
✅ This way Python closes it for you automatically — cleaner and safer.
Example:
Build a simple student note keeper:
1.Ask the user to type their name and a note
2.Save it in a file called notes.txt
3.Each time the app runs, it should add a new line like:
58
Sample Output:
After User runs the app:
59
Mini-Lesson Search or Filter Notes in a File
🎯 Goal:
Ask the user to enter a name
Read the notes.txt file
Show only the notes written by that name
60
Looping through file lines
String functions like .startswith()
Graceful error handling