concept iglob in category data

appears as: iglob
Mastering Large Datasets with Python: Parallelize and Distribute Your Python Code

This is an excerpt from Manning's book Mastering Large Datasets with Python: Parallelize and Distribute Your Python Code.

  • iglob— A function for lazily reading from the filesystem
  • The filter function takes a sequence and restricts it to only the elements that meet a given condition. The zip function takes two sequences and returns a single sequence of tuples, each of which contains an element from each of the original sequences. And the iglob function is a lazy way of querying our filesystem.

    4.4.2. Reading poems in with iglob

    In section 4.2.3, we looked at iglob, a function for searching for files on a filesystem and returning a list of matching paths as an iterable. Because our poets were generous enough to provide us with reams of their unpublished works, we’ll want to use this function to limit the overhead we need to spend storing these paths.

    A straightforward step like this is also something that’s good to get out of the way first. To read in the poems by each author, let’s define two iterables using iglob: one for each author. This is a quick two-liner, as we can see in the following listing.

    Listing 4.6. Listing the authors’ poems using iglob
        author1_poems = iglob("path/to/author_one/*.txt")
        author2_poems = iglob("path/to/author_two/*.txt")