pathlib — the file API AI should reach for first — step 9 of 9
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.)
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.)
this step needs the editor
on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.