Skip to Content
Mastering Python for Networking and Security
book

Mastering Python for Networking and Security

by José Manuel Ortega
September 2018
Intermediate to advanced
426 pages
10h 46m
English
Packt Publishing
Content preview from Mastering Python for Networking and Security

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Python for Networking and Security - Second Edition

Mastering Python for Networking and Security - Second Edition

José Manuel Ortega
Python for Cybersecurity

Python for Cybersecurity

Howard E. Poston, III

Publisher Resources

ISBN: 9781788992510Supplemental Content