quilt
Search…
Filtering a Package
quilt3 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:
1
import quilt3
2
3
# create a package
4
p = (quilt3.Package()
5
.set_dir("foo/", "foo/")
6
.set("bar", "bar"))
7
8
# element-wise transform entries, outputting a list
9
# here "lk" is shorthand for "logical_key"
10
# and "entry" is the package entry
11
p.map(lambda lk, entry: entry)
12
13
# filter out entries not meeting certain criteria
14
p.filter(lambda lk, entry: 'cool' not in lk)
Copied!
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']).
Last modified 1mo ago
Copy link