tabulate
ValueError: headers for a list of dicts is not a dict or a keyword
from: https://bitbucket.org/astanin/python-tabulate/issues/39/valueerror-headers-for-a-list-of-dicts-is
The order of keys in a Python dictionary is undefined in Python 3. So the order of columns in a table given as a list of dicts is not determined either. Thus, if headers are just a sequence of values and data is a list of dicts, there is no sure and portable way to decide what columns the headers correspond to. So tabulate raises a ValueError which asks to use a dict of headers or keywords.
Correct usage with a list of dicts:
tabulate([{'foo': 17, 'bar': 42}], headers={'foo': 'Foo Value', 'bar': 'Bar Count'})
An update. To use dictionary keys as headers, supply headers="keys":
>>> traffic_data = [{"hex":"86da32", "squawk": "0000", "flight": "", "lat": 0, "lon": 0}]
>>> print tabulate(traffic_data, headers="keys")
lat flight squawk hex lon
----- -------- -------- ------ -----
0 0000 86da32 0
最新文章
- java写入文件之txt文本
- Biological Filtration
- Jquery系列教程
- 反射矩阵(reflection matrix)推导
- Flash AS 响应双击事件MouseEvent.DOUBLE_CLICK
- JXL获取excel批注
- iOS:使用导航栏
- JS字符串方法总结整理
- Uva - 11383 - Golden Tiger Claw
- 7.nginx伪静态规则
- React state和props使用场景
- python学习第23天
- 【Java多线程】AtomicLong和LongAdder
- 【洛谷】【二分查找】P1102 A−B数对
- Ubuntu 里面 apt-get 三个有关更新的命令的区别
- Nginx部署vue多项目
- CSS-3 RGBA的使用
- MYSQL的索引类型:PRIMARY, INDEX,UNIQUE,FULLTEXT,SPAIAL 有什么区别?各适用于什么场合?
- POJ 3164 Command Network(最小树形图模板题+详解)
- HTML5的新结构标签
热门文章
- CF438E-The Child and Binary Tree【生成函数】
- YbtOJ#493-最大分数【斜率优化dp,分治】
- 位运算符的用法 ----非(!),与(&;),或(|),异或(^)
- [USACO10NOV]Buying Feed G
- 关于使用antd-vue的卡片无法设置avatar图标/头像问题的解决方案
- WCF服务调用超时错误:套接字连接已中止。这可能是由于处理消息时出错或远程主机超过接收超时或者潜在的网络资源问题导致的。本地套接字超时是“00:05:30”(已解决)
- Apache ShardingSphere 邀您相约 Open Source Day
- Java秘诀!Java关系运算符介绍
- 题解 「BJOI2018 治疗之雨」
- Vuex 基础