files and i/o — moving data in and out8 / 9
open() — and the with-block ai keeps forgetting
Write a small script that:
- Writes the string
"line one\nline two\n"to/tmp/notes.txtusing awithblock in write mode. - Reads the file back with another
withblock and prints its contents stripped of trailing whitespace.
Expected output:
line one
line two
⌘↵ runs the editor.
Booting Python…
Output
[promptdojo:~]$ _