Code Snippets

Author: chris

Walk a Directory Tree

Use os.walk to enumerate every file under a path.

Author: chris

Sort a List of Dicts

Sort a list of dicts by a key with sorted() + itemgetter for speed.

Author: chris

Regex with re.search

Use named groups with the re stdlib and access them via groupdict().

Author: chris

HTTP GET with requests

GET a URL with the requests library and raise on non-2xx.

Author: chris

Write Lines to a File

Open a file for writing and emit a few lines.

Author: chris

Read a File Line by Line

Iterate a text file lazily with a context manager.

Author: chris