Passing parameters in Python

To develop this task, the best thing is to use the argparse module that comes installed by default when you install Python.

For more information, you can check out the official website: https://docs.python.org/3/library/argparse.html.

The following is an example of how to use it in our scripts:

You can find the following code in the filename testing_parameters.py

import argparseparser = argparse.ArgumentParser(description='Testing parameters')parser.add_argument("-p1", dest="param1", help="parameter1")parser.add_argument("-p2", dest="param2", help="parameter2")params = parser.parse_args()print params.param1print params.param2

In the params variable, we have the parameters that the user has entered from the command ...

Get Mastering Python for Networking and Security 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.