Exercise 1 solution: which installed families are monospaced? ============================================================= Save this as mono_scan.py and run it with: py mono_scan.py (It needs fontTools: py -m pip install fonttools) """List the monospaced font families installed in C:/Windows/Fonts.""" from pathlib import Path from fontTools.ttLib import TTFont FONT_DIR = Path("C:/Windows/Fonts") families = {} # family name -> True if monospaced skipped = 0 for path in sorted(FONT_DIR.glob("*.ttf")): try: font = TTFont(path, lazy=True) family = font["name"].getDebugName(1) mono = font["post"].isFixedPitch != 0 except Exception: skipped += 1 continue if family is None: skipped += 1 continue families[family] = families.get(family, False) or mono mono_families = sorted(name for name, is_mono in families.items() if is_mono) print("Monospaced families:") for name in mono_families: print(" ", name) print() print(f"Families found: {len(families)}") print(f"Monospaced: {len(mono_families)} ({len(mono_families) / len(families):.0%})") print(f"Files skipped: {skipped}") Output on the machine this course was written on (Windows 11, Python 3.14.0, fontTools 4.63.0): Monospaced families: Consolas Courier New DFKai-SB Lucida Console Lucida Sans Typewriter SimSun-ExtB SimSun-ExtG Source Code Pro Source Code Pro Black Source Code Pro ExtraLight Source Code Pro Light Source Code Pro Medium Source Code Pro Semibold Families found: 213 Monospaced: 13 (6%) Files skipped: 0 What to take from it -------------------- * A "family" in this script means the name stored in name ID 1. Several of the entries above are really one design in different weights (Source Code Pro appears six times), so the true number of designs is smaller than the number of names. This is the same untidiness the chapter showed with Arial Black. * The fixed-pitch flag is set by the font's author, so it is a claim, not a measurement. Two entries (DFKai-SB and the SimSun ones) are fonts for Chinese text, where the flag means something a little different (check). * Your list will differ: it depends on what is installed on your machine, and some fonts are .otf or .ttc files that this *.ttf scan does not look at. * The takeaway: monospaced fonts are a small minority of what is installed (6% here). They are a specialised tool for code and tables, not an everyday choice for reading.