pathlib — the file API AI should reach for first — step 7 of 9
AI wrote a function that reads a config file and falls back to a
default if the file is missing. Trouble is, the function calls
read_text first and then has nothing to catch the
FileNotFoundError. The script crashes when the path doesn't exist.
Add an if path.exists(): guard so the function returns
"default config" when the file is missing and the file's contents
when it exists.
AI wrote a function that reads a config file and falls back to a
default if the file is missing. Trouble is, the function calls
read_text first and then has nothing to catch the
FileNotFoundError. The script crashes when the path doesn't exist.
Add an if path.exists(): guard so the function returns
"default config" when the file is missing and the file's contents
when it exists.
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.