Glob is an inbuilt Python module that is used to find path names in your filesystem which match a specific pattern. It takes its inspiration from the Unix shell-style of pattern matching.


So, What’s the Use Case?

Ok, we have an idea about the module now but what about the use case? Where might you be able to use this and potentially avoid using a blob of code and instead use glob’s built-in functions to achieve the same task in possibly a single line of code? Let’s take a look.

Use Case: Finding files with a certain extension inside a directory on a filesystem

This is a very common task that can find its use in almost every Python program out there. Let’s say we want to find files with extension .jpeg inside a directory for an image processing task. Let’s try doing that without using glob and then with using glob and see if it’s any better.

#devops #programming #data-science #python3 #python

Use Python’s Built-In Module Glob to Simplify File search
1.15 GEEK