Hello I have a python variable with List plus dictionary
>>> print (b[0])
{'peer': '127.0.0.1', 'netmask': '255.0.0.0', 'addr': '127.0.0.1'}
-----------------------------------------------------------------------
>>> print (b)
[{'peer': '127.0.0.1', 'netmask': '255.0.0.0', 'addr': '127.0.0.1'}]
>>>
I have tried everything But I couldn't get 'addr'
extracted.
Help Please.
try this:
print (b[0]['addr'])
print(b[0]) gives a dictionary, in dictionary you can fetch the value by its key like dict[key] => returns its associated value.
so
print(b[0]['addr'])
will give you the value ofaddr
Read about python data structure here Data structure
print list by its key
print(b[0]['addr'])
You can just use a print(b[0]['addr'])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With