files and i/o — moving data in and out9 / 9
pathlib — the file api ai should reach for first
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. Write a function merge_logs(folder) that:
- Globs for all
*.logfiles infolder(sorted by name). - Reads each file's text.
- Returns a single string with the contents of all logs joined, each separated by a single newline. Trailing newlines are fine.
The starter creates three log files. Calling the function should print exactly:
--a--
--b--
--c--
(Each file's content is --<letter>--\n. Concatenated they form
three lines.)
⌘↵ runs the editor.
Booting Python…
Output
[promptdojo:~]$ _