import json
import itertools
with open('test.json') as json_file:
for _ in itertools.repeat(None, 10):
json_data = json.load(json_file)
print(json_data)
或者更简单:
import json
with open('test.json') as json_file:
for _ in xrange(10):
json_data = json.load(json_file)
print(json_data)
没有循环。
with
不是循环,if
也不是循环。你知道吗看起来您缺少
for
语句。你知道吗另外,还有一种更像Python的做事方式:
或者更简单:
相关问题 更多 >
编程相关推荐