Closed lowfell closed 3 years ago
Hello. Can anyone help here?
Hi @lowfell -- I think you're working with the XML file at https://github.com/hpreston/python_networking/blob/master/data_manipulation/xml/xml_example.xml -- if so, then you need to get the next-nested line of data from line 9:
<netmask>255.255.255.0</netmask>
The "OrderedDict" that Python sees still contains <ip>172.16.0.2</ip><netmask>255.255.255.0</netmask>
and what you want to do is get xml_dict
to give you the netmask
instead of the ip
within address
.
So you can replace ["ip']
with ["netmask"]
to match the XML data as it's given:
test_address = xml_dict["interface"]["ipv4"]["address"]["ip"]
test_netmask = xml_dict["interface"]["ipv4"]["address"]["netmask"]
print("test_address is: " + test_address)
print("test_netmask is: " + test_netmask)
Let me know if that makes sense.
Hi @lowfell -- I think you're working with the XML file at https://github.com/hpreston/python_networking/blob/master/data_manipulation/xml/xml_example.xml -- if so, then you need to get the next-nested line of data from line 9:
<netmask>255.255.255.0</netmask>
The "OrderedDict" that Python sees still contains
<ip>172.16.0.2</ip><netmask>255.255.255.0</netmask>
and what you want to do is getxml_dict
to give you thenetmask
instead of theip
withinaddress
.So you can replace
["ip']
with["netmask"]
to match the XML data as it's given:test_address = xml_dict["interface"]["ipv4"]["address"]["ip"] test_netmask = xml_dict["interface"]["ipv4"]["address"]["netmask"] print("test_address is: " + test_address) print("test_netmask is: " + test_netmask)
Let me know if that makes sense.
Hello and thanks again for your help. I'm maybe explaining myself wrong. what I'm after is to create a query from the xml file using _whatevername that will return the ip address AND the subnet mask in one query so if i type in _whatevername 172.16.0.2 255.255.255.0
In this leasson it only returns ONE piece of information like the ip address OR the subnet mask
Can i do this using the same type of logic in this lesson, as that would be more beneficial from the point of view of a network engineeer, if you know what I mean?
The data you are handed is the pattern you must work with. So yes, you can make address_netmask
(or "whatever_name") your new variable by making the concatenation of those two variables test_address
plus test_netmask
and converting to a string and adding a space when you want to print it exactly as you want it:
address_netmask = str(xml_dict["interface"]["ipv4"]["address"]["ip"]) + " " + xml_dict["interface"]["ipv4"]["address"]["netmask"]
print(address_netmask)
But maybe I'm misunderstanding your question -- I'm explaining how to get a string instead of a dictionary, with a one-liner, but you might need something else in your context so feel free to keep asking questions. 🔬
So whilst you've given me a string which gives me what i want this isn't like you say not from a dictionary? so, the way i was tring it the nearest I got to it was test8 = xml_dict["interface"]["ipv4"]["address"] test8 OrderedDict([('ip', '172.16.0.2'), ('netmask', '255.255.255.0')])
whilst this returned the data i wanted which was 172.16.0.2 255.255.255.0 it also returned all the stuff i dont really want like all the brackets and the names OrderedDict, ip and netmask ? so are we saying there is no way round this?
Also From a github point of view am i ok to be asking these questions and if i am am i asking in the right place? If im not supposed to be asking questions where can i go for help?
Thanks again
I would definitely point you to the DevNet community forums and chatrooms on Webex -- click through the options on this page: https://developer.cisco.com/site/support/.
We use GitHub Issue comments to make sure our content and code examples are accurate so it's also okay to double-check if examples aren't working as expected. But yes, in this case, the example is working as expected and you can get more and better discussion and support through the usual DevNet Support channels.
Apologies and thanks again for your help and patience. I'll be asking my queries on the community now. Brian
Sent from Workspace ONE Boxer
On 9 Jan 2021 02:41, Anne Gentle notifications@github.com wrote:
I would definitely point you to the DevNet community forums and chatrooms on Webex -- click through the options on this page: https://developer.cisco.com/site/support/.
We use GitHub Issue comments to make sure our content and code examples are accurate so it's also okay to double-check if examples aren't working as expected. But yes, in this case, the example is working as expected and you can get more and better discussion and support through the usual DevNet Support channels.
Save Paper - Do you really need to print this e-mail?
Visit www.virginmedia.com for more information, and more fun.
This email and any attachments are or may be confidential and legally privileged and are sent solely for the attention of the addressee(s).
Virgin Media will never ask for account or financial information via email. If you are in receipt of a suspicious email, please report to www.virginmedia.com/netreport
If you have received this email in error, please delete it from your system: its use, disclosure or copying is unauthorised. Statements and opinions expressed in this email may not represent those of Virgin Media. Any representations or commitments in this email are subject to contract.
Registered office: 500 Brook Drive, Reading, RG2 6UU
Registered in England and Wales with number 2591237
Hello all I'm a total newby so bear with me. i'm trying to do the xmltodict example in Useful Python Libraries for Network Engineers
I kind of get how it works and i ran a query myself to get the ip address so here is the xml that he uses
**Here is the query to generate an ip address notice how it is in the order of the info top down from the xml
Here is the query ran
This only returns the ip address. How would i make the query return the ip address and the netmask ie 172.16.0.2 255.255.255.0 ?
I've tried lots of combinations the nearest i could get to it is
how do i get it with just 172.16.0.2 255.255.255.0 ?