flask - python 多维字典遍历

 无心少年丶的诱惑 发布于 2022-10-26 17:41

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}}

现在想遍历这个字典:


 {% for ni in net_interfaces %}
   
   {% endfor %}
   
Interface IP RX/s TX/s
{{ ni }} {{ ni.ip }} {{ ni.send_rate|default(0)|filesizeformat }} {{ ni.recv_rate|default(0)|filesizeformat }}

但是这样遍历数组好像不行耶,求指点

4 个回答
  • for key, value in data.items

    2022-10-27 01:05 回答
  • for i in data:
        print i,data[i],data[i].j
    2022-10-27 01:06 回答
  • for key,value in data

    2022-10-27 01:06 回答
  • {% for ni in net_interfaces.lo0 %}

    2022-10-27 01:07 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有