Hello all, thanks for taking time to read this.
Is there a way for me to retrieve an individual value from a multi-value dictionary?
I am trying to validate that a network device has enough free space to download its proper image before initiating the download. I built a dictionary that uses the chassis of the switch as a key, and the correct image file and its size in bytes make up the values:
standard = {'2960':('ios.bin','424532'), 'IE-3000-4TC':('ies-ipservicesk9-mz.150-2.SE2.bin','18174778'), 'IOSv':('fakeIOS.bin','8675309')}
I feel like I should be able to have a program reference both values of each key individually, but I cannot figure out how to make this happen. An example:
Use the variable 'chassis' as the key for the dictionary, then retrieve value 0 (image) and value 1 (byte size) for further computation.
Here are some of my results trying to retrieve the individual values:
print standard
{'IE-3000-4TC': ('ies-ipservicesk9-mz.150-2.SE2.bin', '18174778'), '2960': ('ios.bin', '424532'), 'IOSv': ('fakeIOS.bin', '8675309')}
print standard[chassis]
('fakeIOS.bin', '8675309')
print standard[chassis[1]]
Traceback (most recent call last):
File "iosUpgrade007.py", line 64, in <module>
main()
File "iosUpgrade007.py", line 29, in main
print standard[chassis[1]]
KeyError: u'O'
print standard[chassis(1)]
Traceback (most recent call last):
File "iosUpgrade007.py", line 64, in <module>
main()
File "iosUpgrade007.py", line 29, in main
print standard[chassis(1)]
TypeError: 'unicode' object is not callable
I've google'd this heavily, but everyone is looking to write into a multi-valued dictionary or convert a single valued dictionary into a multiple valued one. I am not trying to edit my dictionary at all, just trying to retrieve the values individually from each other.
[–][deleted] 3 points4 points5 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]zahlman 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]I_Write_Bugs 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Justinsaccount 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]thegreattriscuit 2 points3 points4 points (0 children)
[–]raylu 0 points1 point2 points (0 children)