Understanding Argparse – argument_parser.py

Argparse is a module in the standard library and will be used throughout this book as a means of obtaining user input. Argparse can help develop more complicated command-line interfaces. By default, argparse creates a -h switch or a help switch to display help and usage information for the scripts. In this section, we will build a sample argparse implementation that has required, optional, and default arguments.

We import the argparse module, following our usual print_function and script description. We then specify our usual script header details as __author__, __date__, and __description__ as we will be using all three in our argparse implementation. On line 38, we then define an overly simple ...

Get Learning Python for Forensics - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.