您的位置:首頁技術文章
文章詳情頁

flask - python 多維字典遍歷

瀏覽:87日期:2022-08-10 16:36:31

問題描述

python多維數組遍歷問題:

net_interfaces:{’lo0’: {’name’: ’lo0’, ’ip’: ’fe80::1%lo0’, ’bytes_sent’: 79486408, ’bytes_recv’: 79486408, ’packets_sent’: 59982, ’packets_recv’: 59982, ’errors_in’: 0, ’errors_out’: 0, ’dropped_in’: 0, ’dropped_out’: 0}}

現在想遍歷這個字典:

<table class='table'> <thead> <tr> <th>Interface</th> <th>IP</th> <th>RX/s</th> <th>TX/s</th> </tr> </thead> <tbody> {% for ni in net_interfaces %} <tr> <td>{{ ni }}</td> <td>{{ ni.ip }}</td> <td>{{ ni.send_rate|default(0)|filesizeformat }}</td> <td>{{ ni.recv_rate|default(0)|filesizeformat }}</td> </tr> {% endfor %} </tbody></table>

但是這樣遍歷數組好像不行耶,求指點

問題解答

回答1:

{% for ni in net_interfaces.lo0 %}

回答2:

for key,value in data

回答3:

for i in data: print i,data[i],data[i].j回答4:

for key, value in data.items

標簽: Python 編程
相關文章:
国产综合久久一区二区三区