Best Practices for Python Scripting
summary
Starts from a Python REPL solving "top 10 words" in the Gettysburg Address, then refactors the session into functions for retext, count_words and sort_words, uses collections.defaultdict and sorted with operator.itemgetter, adds argparse for infile/outfile and a count option, supports stdin/stdout, reads environment variables and config files via os.environ and ConfigParser, packages the script with setuptools entry_points as a console_scripts command, and ensures proper exit codes via sys.exit.
AI-written summary · about
chapters (11)
- 0:00Start
- 2:49Collections Module
- 3:06Default Dictionary
- 14:42Pipe Data between Commands
- 24:14Environment Variables
- 24:35Environment Variable Parsing
- 30:25Fake Parser
- 35:37Using the Return Value from Program
- 38:40Entry Points
- 42:11Python Startup
- 42:30Read in History File
related talks
59mFun with Python's newer tools
02h 17mIntro to Python for Brand New Programmers
01h 26mPackage Your Python Code as a CLI
27mCommand line programs for busy developers
52mPython Tips, Tricks, and Idioms
36mCLI applications & TDD: Never write scripts again
27mDream in Code
33mUpgrading Python CLIs From Scripts to Interactive Tools
