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 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.