Python file modes: activity sheet
Goal: See what the open() modes r, w, a and r+ do to a text file that exists or is missing.
You need: Only the simulation is needed. You can repeat it later in Python with a scratch file.
Safety: No special safety needs.
- Open the existing file with 'r' and note what changes.
- Open it with 'w' and write HELP.
- Repeat with 'a' and 'r+'.
- Try 'r' on a missing file and record the error.
| Mode | File existed | Text written | Result in file |
|---|---|---|---|
Use your browser's Print option to print this page.