Pybites Logo

User experience matters! suggest matching files

Level: Intermediate (score: 3)

We love it when CLI or web apps take the extra mile to be more user friendly. In this Bite you will tweak the user experience of a function yourself.

Have you noticed how Django's migrate.py helps you type in the right command?

$ python manage.py migrat
Unknown command: 'migrat'. Did you mean migrate?
Type 'manage.py help' for usage.

Using Python's difflib this is actually not that hard to implement. Let's roll our own using another theme: file matching.

Complete the get_matching_files function below. It takes a target directory Path object and filter_str str to match (case insensitive). If any files match exactly, return a list with matches. If there is no exact match, see if there are closely matching files and return those. If no closely matching files either, return an empty list.

Good luck and keep calm and code more Python!