SE-05 Python Tutorial: Working with Files in Python - Searching File using glob module in python

Опубликовано: 19 Март 2023
на канале: NeoKloud
22
1

The glob module in Python provides a way to find files and directories whose names match a specified pattern. It is useful for searching for files with specific extensions, finding files that match a certain naming convention, or locating files that have a specific prefix or suffix in their names.

The glob module provides two functions for searching for files: glob() and iglob(). Here's a brief overview of each function:

glob(pathname, *, recursive=False): Returns a list of all the file pathnames that match the specified pattern in the given pathname. If recursive is set to True, it will search for files recursively in all subdirectories as well. The returned paths are sorted in alphabetical order.

iglob(pathname, *, recursive=False): This function returns an iterator that yields the file pathnames that match the specified pattern in the given pathname. If recursive is set to True, it will search for files recursively in all subdirectories as well. Unlike glob(), this function returns an iterator, which makes it more memory-efficient for working with large file collections.

Both functions use the same syntax for patterns. The pattern is specified as a string with wildcard characters such as * (matches zero or more characters), ? (matches any single character), and [] (matches any character in a set).


На этой странице сайта вы можете посмотреть видео онлайн SE-05 Python Tutorial: Working with Files in Python - Searching File using glob module in python длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь NeoKloud 19 Март 2023, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 22 раз и оно понравилось 1 зрителям. Приятного просмотра!