【发布时间】:2018-03-22 05:49:24
【问题描述】:
脚本语言:Python 3.6
参考书:Python 数据可视化食谱 [Milovanović 2013-11-25]
自学 Python 数据可视化
当我从书中执行代码时
import requests
url = 'https://github.com/timeline.json'
r = requests.get(url)
json_obj = r.json()
repos = set() # we want just unique urls
for entry in json_obj:
try:
repos.add(entry['repository']['url'])
except KeyError as e:
print ("No key %s. Skipping..." % (e))
from pprint import pprint
pprint(repos)
我得到错误
repos.add(entry['repository']['url'])
TypeError: string indices must be integers
如何排除故障?当我看到similar threads 时,我画了一个空白
书中的代码是否正确?
[顺便说一句,repos = set() 中的 set() 是从哪里来的?]
请指出正确的方向
【问题讨论】:
-
来自 json_obj:你好,远行的陌生人。如果您正在阅读本文,那么您可能在几年前没有看到我们的博客文章宣布此 API 将消失:git.io/17AROg 不要害怕,您应该能够从闪亮的新事件 API 中获得所需的东西而是。