Appendix. Using argparse

Often, getting the right data into your program is a real chore. The argparse module makes it much easier to validate arguments from users and to generate useful error messages when they provide bad input. It’s like your program’s “bouncer,” only allowing the right kinds of values into the program. Defining the arguments properly with argparse is the crucial first step to making the programs in this book work.

For instance, chapter 1 discusses a very flexible program that can extend warm salutations to an optionally named entity, such as the “World” or “Universe”:

$ ./hello.py                       Hello, World! $ ./hello.py --name ...

Get Tiny Python Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.