Automating the Mundane: What a 2016 German Python Book Still Teaches Us About Practical Programming

The Pitch: Programming as a Lever, Not a Career

When the German edition of Automate the Boring Stuff with Python landed in 2016, it carried a clear thesis: programming literacy should work like a pocketknife for office workers, researchers, and administrators – sharp, accessible, and ready for the specific job at hand. Al Sweigart frames coding not as a pathway to software engineering but as a practical lever for “throwaway code” that solves single, well-defined problems: batch renaming hundreds of files, scraping a price list from a website, merging PDFs, or filling a web form that refuses to remember your data.

The opening anecdote sets the tone. A novice writes a script that reduces a two-day manual price-comparison job to seconds. The story is anecdotal, but it illustrates the book’s core promise: a small amount of Python knowledge, applied directly to a tedious workflow, can yield disproportionate returns.

Pedagogical Trade-offs by Design

Sweigart makes deliberate sacrifices to lower friction for beginners. The code uses global variables, minimal error handling, and camelCase instead of the Python community’s preferred snake_case. Object-oriented programming, generators, list comprehensions, testing frameworks, and version control are absent. The author acknowledges these choices will irritate experienced programmers but argues they serve a purpose: immediate runnability.

Programs are presented in a “copy-paste-run” style with step-by-step projects that reinforce transferable patterns over theory. Debugging is taught as patient observation; logging and assert are preferred over print() statements. The author claims programming requires no more math than basic arithmetic, likening it to Sudoku – logic and step decomposition, not calculation.

Building a Mental Model, Chapter by Chapter

The first six chapters construct a coherent mental model through the REPL. Variables become labeled memory containers. Expressions reduce to single values. Core types (int, float, str), Boolean logic with explicit precedence, flow control (if/elif/else, while, for/range), functions as black boxes returning None, scope as a compile-time property, exceptions as control-flow tools, and compound data structures (lists, tuples, dictionaries) all build incrementally.

The author consistently distinguishes language guarantees from recommendations: avoid duplication, avoid globals, use import module over from module import *. This clarity helps beginners separate what Python requires from what the community suggests.

The Automation Stack: One Library per Domain

Part II maps each automation domain to a specific library, creating a practical toolkit:

  • Text and pattern matching: re for regular expressions, pyperclip for clipboard I/O
  • Filesystem operations: os, shutil, send2trash, zipfile
  • Persistence: shelve (pickle-backed) for simple object storage, pprint.pformat for writing importable Python modules
  • Web scraping: requests + BeautifulSoup for static pages, Selenium for JavaScript-heavy sites
  • Office documents: openpyxl (Excel), PyPDF2 (PDF), python-docx (Word)
  • Structured data: csv and json modules
  • Time and concurrency: time, datetime, threading, subprocess
  • Messaging: smtplib/imapclient/pyzmail (email), twilio (SMS)
  • Images and GUI automation: Pillow (RGBA, drawing, batch watermarking), PyAutoGUI (mouse, keyboard, screen)

Each library gets a dedicated chapter with a complete, runnable project. The census aggregator reads 3,000+ rows from an Excel file, builds a nested dictionary with setdefault(), and writes the result as a Python module via pprint.pformat. The produce price correction replaces hardcoded conditionals with a PRICE_UPDATES dictionary. The PDF combiner sorts files, skips first pages, and merges the rest. The Word invitation generator uses python-docx runs with bold/italic/None inheritance and page breaks.

Defensive Practices That Scale Down

The book introduces assertions for internal invariants (disabled with python -O), logging with five severity levels and logging.disable() for global silencing, traceback capture via traceback.format_exc(), and IDLE’s breakpoint debugger (Step/Over/Out/Go). A traffic-light simulator demonstrates how silent logic errors cause catastrophic failures without crashing; an assertion triggers at the exact failure point.

The author draws a sharp line: exceptions should be caught; assertions should not. Logging is positioned as superior to print() for configurable verbosity and timestamps. These practices, while basic, give beginners a vocabulary for reliability that transfers to larger codebases.

Cross-Cutting Themes: References, Immutability, Platforms

Several concepts recur across domains. Strings and tuples are immutable; lists and dictionaries are mutable. Variables hold references; cheese = spam copies the reference, not the object. copy.copy() (shallow) versus copy.deepcopy() (recursive) becomes essential when nested structures enter the picture.

Function parameters receive reference copies. Mutating a list inside a function affects the caller’s object; reassignment replaces the reference. Platform abstraction appears in os.path.join for paths, open(…, newline=”) on Windows for CSV, subprocess.Popen with shell=True on Windows for the start command. Notably, pathlib (standard since Python 3.4) is not discussed – a casualty of the edition’s vintage.

Security Caveats, Clearly Labeled

The book does not ignore security. shelve/pickle risks with untrusted data are noted. Plaintext password storage in a pw.py module is explicitly labeled insecure. Gmail’s shift to app-specific passwords and OAuth2 is mentioned, though the examples predate widespread OAuth2 adoption. The imaplib._MAXLINE workaround for bulk fetches is documented as a practical necessity.

Projects That Chain Tools Into Workflows

The book’s greatest practical value lies in integrated, runnable projects that chain standard-library and third-party tools into complete workflows:

  • Multi-clipboard (mcb.pyw): shelve + command-line arguments (save <keyword>, <keyword>, list); .pyw suppresses the console on Windows.
  • US-to-EU date renaming: Verbose regex with numbered groups for beforePart, monthPart, dayPart, yearPart, afterPart; shutil.move() after printed preview.
  • Folder-to-ZIP backup: while True + os.path.exists() for incremental numbering, os.walk() traversal skipping prior backups.
  • Web scraping: mapIt.py reduces a seven-step Google Maps lookup to two (copy address, run script). downloadXkcd.py follows “Prev” links iteratively, selects #comic img, writes in 100 KB chunks. lucky.py opens top five Google results via a brittle .r a selector.
  • Multithreaded XKCD downloader: 1,400 comics divided among 14 threads (100 each), join() synchronization; GIL noted as CPU bottleneck.
  • Batch watermark: Resize longer dimension to 300px proportionally, paste transparent logo at bottom-right using logo as mask (paste(logo, (x,y), logo)).
  • Form filler: Coordinates captured via mouseNow.py; 5-second startup pause, PAUSE=0.5, pixelMatchesColor loop waits for submit button RGB (75,141,249); keyboard navigation (Tab, down-arrow, space) for dropdowns and radio buttons.

The Edition Lag: What’s Missing

The 2016 German edition lags behind the 2nd and 3rd English editions. Missing are pathlib, openpyxl 3.x updates, pandas examples, asyncio, modern editors (VS Code, PyCharm), virtual environments, and argparse. Deprecated APIs appear throughout: Selenium find_element_by_* (replaced by find_element(By.ID, …)), openpyxl get_sheet_by_name(), get_highest_row(), Style(font=…) (replaced by wb[‘Sheet’], sheet.max_row, cell.font), python-docx v0.7.4’s inability to create styles programmatically.

Library versions are unstated; APIs may have shifted. Platform abstraction gaps persist: Windows/macOS/Linux path differences are noted but not abstracted; os.chdir() affects all threads. Error handling stops at try/except and assert; no testing frameworks, no try/except for conversion errors (int(‘99.99’)), no network/rate-limit handling in scraping/email examples.

Code Style: Honest About Its Limits

The author admits the code style – global variables, minimal error handling, camelCase – is unsuitable for production or team environments. This honesty is refreshing. The book positions itself as a launchpad, not a destination. Readers who outgrow it will need to adopt pathlib, venv, requirements.txt, type hints, and threat modeling for credential handling.

What Remains Immediately Useful

Despite its age, the book delivers runnable scripts for batch file operations (rename, move, ZIP, delete with send2trash), spreadsheet/text parsing (Excel price updates, census aggregation, CSV header removal), automated backups (incremental ZIP with os.walk), clipboard utilities (multi-clipboard, bullet-point adder, regex extraction), web scraping (static via requests/BeautifulSoup, dynamic via Selenium), scheduled downloads (threaded XKCD, time.sleep loops, OS schedulers), email/SMS alerts (SMTP TLS 587, IMAP search with imapclient, Twilio SMS), image manipulation (resize, watermark, draw/text via ImageDraw/ImageFont), and GUI-driven data entry (form filler with coordinate capture, pixel-color waits).

The English text is freely available under Creative Commons at inventwithpython.com, mitigating the German edition’s lag for readers comfortable with English.

Translating to Modern Practice

Modern readers must translate deprecated Selenium and openpyxl calls, adopt pathlib/venv/asyncio, and supply missing security/error-handling layers. The edition’s lag, unstated library versions, and platform-specific examples are the primary limitations for production use. But as a project-driven curriculum for non-programmers who want to eliminate repetitive computer tasks without becoming software engineers, it remains a remarkably dense, practical reference – one that respects the reader’s time by delivering working code first and theory later.

Leave a Reply