Skip to content
This repository has been archived by the owner on Jun 4, 2019. It is now read-only.

Latest commit

 

History

History
20 lines (15 loc) · 802 Bytes

Filtering a Package.md

File metadata and controls

20 lines (15 loc) · 802 Bytes

t4 provides a handful of functions for operating on the contents of a package in an entry-by-entry manner. These are helpful for performing more complicated parsing operations on the package:

import t4

# create a package
p = (t4.Package()
        .set_dir("foo/", "foo/")
        .set("bar", "bar"))

# element-wise transform entries, outputting a list
# here "lk" is shorthand for "logical_key"
# and "entry" is the package entry
p.map(lambda lk, entry: entry)

# filter out entries not meeting certain criteria
p.filter(lambda lk, entry: 'cool' not in lk)

Notice that these functions operate over (logical_key, entry) tuples. Each logical_key is a string. Each entry is PackageEntry object, as would be returned if you slice to a leaf node of the package (e.g. p['bar']).