Which three statements about using Python for device inventory and data serialization in network automation are true? (Choose three.)
Trap 1: YAML files in Python cannot contain comments, so all inventory data…
Incorrect because YAML supports comments using the '#' character, and Python's PyYAML library can parse files that include comments (though comments are not preserved when dumping).
Trap 2: JSON is always more human-readable than YAML for complex inventory…
Incorrect because YAML is often considered more human-readable due to its use of indentation and less verbose syntax; JSON can be harder to read for deeply nested structures.
- A
A Python script can read a YAML file containing device hostnames and IP addresses, then use that data to connect to each device and gather inventory information.
Correct because this is a common pattern: use PyYAML to load a YAML inventory file, iterate over devices, and use Netmiko or NAPALM to collect facts.
- B
The json module in Python can be used to serialize a dictionary containing device inventory data into a JSON string for storage or transmission.
Correct because Python's built-in json module provides json.dumps() to convert Python objects (like dicts) into JSON strings, which is useful for saving inventory data or sending it to other systems.
- C
CSV files can be parsed using Python's csv module to import device inventory data, such as hostname, IP, and credentials, into a script.
Correct because the csv module allows reading and writing CSV files, which are commonly used for inventory lists in network automation.
- D
YAML files in Python cannot contain comments, so all inventory data must be described without explanatory text.
Why wrong: Incorrect because YAML supports comments using the '#' character, and Python's PyYAML library can parse files that include comments (though comments are not preserved when dumping).
- E
JSON is always more human-readable than YAML for complex inventory structures.
Why wrong: Incorrect because YAML is often considered more human-readable due to its use of indentation and less verbose syntax; JSON can be harder to read for deeply nested structures.