Python has several built-in methods for modifying and manipulating strings. Two of these methods, - startswith( ) and endswith( ) - are useful when we are searching filenames. To do this, first get a directory listing and then iterate over it.
import os
for f_name in os.listdir('routes'):
if f_name.endswith('.py'):
print(f_name)
The code above finds all the files in routes directory to iterate over them using endswith( ) to print out the filenames that have the .py file extension.