April 2017
Beginner to intermediate
312 pages
7h 23m
English
The glob module (https://docs.python.org/3/library/glob.html) enables identifying files of a specific extension or files that have a specific pattern. For example, it is possible to list all Python files in a folder as follows:
# List all filesfor file in glob.glob('*.py'): print(file)
The glob() function returns a list of files that contains the .py extension. A for loop is used to iterate through the list and print each file. When the preceding code snippet is executed, the output contains the list of all code samples belonging to this chapter (output truncated for representation):
read_from_file.pyconfig_parser_read.pyappend_to_file.pyread_line_from_file.pyconfig_parser_modify.pypython_utils.pyconfig_parser_write.py ...
Read now
Unlock full access