Python 打印我的提要的前10行
我试图只打印前10行数据。我尝试了“枚举”和其他代码,但它们似乎都不起作用。关于如何只获取输出的前10个标题,您有什么想法吗?使用Python 打印我的提要的前10行,python,json,feed,Python,Json,Feed,我试图只打印前10行数据。我尝试了“枚举”和其他代码,但它们似乎都不起作用。关于如何只获取输出的前10个标题,您有什么想法吗?使用[:10]作为一个片段,您将获得前10个元素: import json with open('output.json', encoding='utf-8') as json_file: output = json.loads(json_file.read()) feeds = [] for feed in output ['posts']: fee
[:10]
作为一个片段,您将获得前10个元素:
import json
with open('output.json', encoding='utf-8') as json_file:
output = json.loads(json_file.read())
feeds = []
for feed in output ['posts']:
feeds.append (feed)
print (feeds[1]['title'])
导入json
将open('output.json',encoding='utf-8')作为json\u文件:
output=json.load(json_file.read())
提要=[]
对于feed-in输出['posts'][:10]:#使用[:10]
作为一个片段将使您获得前10个元素:
import json
with open('output.json', encoding='utf-8') as json_file:
output = json.loads(json_file.read())
feeds = []
for feed in output ['posts']:
feeds.append (feed)
print (feeds[1]['title'])
导入json
将open('output.json',encoding='utf-8')作为json\u文件:
output=json.load(json_file.read())
提要=[]
对于输入输出['posts'][:10]:#输入输出['posts'][:10]
?输入输出['posts'][:10]
?你好,Alex感谢您的回复。您建议的代码仍然只打印提要[1]所示的第一行。如果我想要前10行数据,我该怎么办?嗨,我尝试了以下方法,效果很好:feed=[]对于feed-in-output['posts'][:10]:print(str(feed['title']))feed.append(feed)嗨,Alex谢谢你的回复。您建议的代码仍然只打印提要[1]所示的第一行。如果我想要数据的前10行,我应该怎么做?嗨,我尝试了下面的方法,效果很好:feed=[]对于feed-in-output['posts'][:10]:print(str(feed['title'])feed.append(feed)