files and i/o — moving data in and out9 / 9
open() — and the with-block ai keeps forgetting
Checkpoint
One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.
Last drill — the JSON pattern AI uses on every config file.
- Import
json. - Write a dict
{"app": "promptdojo", "users": 1}to/tmp/config.jsonusingjson.dump(data, f)inside awithblock. - Read it back with
json.load(f). - Print the value of the
"app"key.
Expected output:
promptdojo
⌘↵ runs the editor.
Booting Python…
Output
[promptdojo:~]$ _