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

最新文章

  1. java写入文件之txt文本
  2. Biological Filtration
  3. Jquery系列教程
  4. 反射矩阵(reflection matrix)推导
  5. Flash AS 响应双击事件MouseEvent.DOUBLE_CLICK
  6. JXL获取excel批注
  7. iOS:使用导航栏
  8. JS字符串方法总结整理
  9. Uva - 11383 - Golden Tiger Claw
  10. 7.nginx伪静态规则
  11. React state和props使用场景
  12. python学习第23天
  13. 【Java多线程】AtomicLong和LongAdder
  14. 【洛谷】【二分查找】P1102 A−B数对
  15. Ubuntu 里面 apt-get 三个有关更新的命令的区别
  16. Nginx部署vue多项目
  17. CSS-3 RGBA的使用
  18. MYSQL的索引类型:PRIMARY, INDEX,UNIQUE,FULLTEXT,SPAIAL 有什么区别?各适用于什么场合?
  19. POJ 3164 Command Network(最小树形图模板题+详解)
  20. HTML5的新结构标签

热门文章

  1. CF438E-The Child and Binary Tree【生成函数】
  2. YbtOJ#493-最大分数【斜率优化dp,分治】
  3. 位运算符的用法 ----非(!),与(&),或(|),异或(^)
  4. [USACO10NOV]Buying Feed G
  5. 关于使用antd-vue的卡片无法设置avatar图标/头像问题的解决方案
  6. WCF服务调用超时错误:套接字连接已中止。这可能是由于处理消息时出错或远程主机超过接收超时或者潜在的网络资源问题导致的。本地套接字超时是“00:05:30”(已解决)
  7. Apache ShardingSphere 邀您相约 Open Source Day
  8. Java秘诀!Java关系运算符介绍
  9. 题解 「BJOI2018 治疗之雨」
  10. Vuex 基础