是否有更好/更干净/更短的方法来获得与以下相同的输出?在
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
我试过:
^{pr2}$但我得到:
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'
你只需要:
由于
pl
是一个列表,遍历该列表将依次给出每个子字典。在一个简单的例子:
^{pr2}$您可以使用>;>>for in<;<;<;语句
http://docs.python.org/tutorial/controlflow.html#for-statements
pl是一个列表,而不是字典。在
因此,您应该通过以下方式迭代pl:
相关问题 更多 >
编程相关推荐