Paul's Python CoursePPC

Paths

Not met yet

A Path from pathlib is a file name that understands itself. Path("records") / "loans.csv" joins a folder and a file the right way, .exists() says whether it's there, and .name, .stem and .suffix pick the name apart. A name with no folder in front is relative: it means the folder the program is running in.

Try it

main.py

Output

Press Run and what your program prints shows up here.

Easy to get wrong

  • Thinks / between a Path and a string divides, or is an error, rather than joining folder and file.
  • Thinks .suffix gives a file's extension without its dot.
  • Thinks a file name with no folder is looked for all over the computer, rather than in the folder the program runs in.

Where it comes up