To use the functions of another Python file, you import this file.
A file that you import is called a module, and there are two ways to import it:
Figure 1 - Two Ways to Import a Module
In the lab, the file
utils.pyholds the functionport_name.
Import it indeploy.pyand print the name of port 7 to get the flag.Answer the question below
Enter the flag you obtained.
To make your own module, you move your functions to a new file.
Every script can then import them:
Figure 2 - A Function in Its Own File
The module and the script must be in the same folder.
In the lab, move the function
save_configfromdeploy.pyto the fileutils.py.
Import it indeploy.pyto get the flag.Answer the question below
Enter the flag you obtained.
Python comes with many modules that are ready to import.
They are the standard library:
Figure 3 - Where Modules Come From
The module
ipaddressknows how to work with networks:import ipaddress network = ipaddress.ip_network("192.168.1.0/24") print(network.num_addresses) # Output: 256In the lab, print the number of addresses of the network 10.0.0.0/26 to get the flag.
In the editor, you can hold Ctrl and click the name of a module to open it and see what it holds.
Answer the question below
Enter the flag you obtained.
Some modules do not come with Python.
They are in packages that you install, like Netmiko:
Figure 4 - Packages Are Installed with pip
To install a package, you use the program
pipin the terminal like this:netops@automation:~/automation$ pip install netmikoIn this environment, Netmiko is already installed, so
piponly answers that it is already there.
In the lab, usepip show netmikoto answer the question.Answer the question below
Which version of Netmiko is installed?