Is there a better / cleaner / shorter way of getting the same output as the following?
import plistlib
pl = plistlib.readPlist('/Users/username/Documents/wifi1.plist')
n = len(pl)
count = 0
while (count < n):
print('----------------')
print(pl[count]['NOISE'])
print(pl[count]['RSSI'])
print(pl[count]['SSID_STR'])
print(pl[count]['BSSID'])
count += 1
I have tried:
for sub_dict in pl.values():
print(sub_dict['NOISE'], sub_dict['RSSI'], sub_dict['SSID_STR'], sub_dict['BSSID'])
but I get:
Traceback (most recent call last):
File "plistread.py", line 17, in <module>
for sub_dict in pl.values():
AttributeError: 'list' object has no attribute 'values'
You just need:
Since
plis a list, iterating through that list will give you each sub dictionary in turn.A simple example: