从文件中读取一个键的值并将一个随机数输出到一个文件中?

2024-10-01 09:25:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一打文件,结构如下:

{"reviewerID": "A4IL0CLL27Q33", "asin": "104800001X", "reviewerName": "D. Brennan", "helpful": [0, 1], "reviewText": "I hate it when my shirt collars, not otherwise secured in place by buttons, end up in weird places throughout the day. I purchased some steel collar stays to use with these magnets but they were only vaguely magnetic. I ended up using 2 of these magnets - one in the collar with the stay and the other inside my shirt, to lock my collar in place. They work flawlessly. They are the perfect size, and there are plenty of magnets in case you forget to remove them at the end of the day.", "overall": 5.0, "summary": "Perfect for collar stay management", "unixReviewTime": 1390953600, "reviewTime": "01 29, 2014"}
{"reviewerID": "A3Q5W5E7TDVLJF", "asin": "104800001X", "reviewerName": "funnyc130", "helpful": [0, 0], "reviewText": "These little magnets are really powerful for there size. I am using them to make secret compartments in custom made boxes. Each one hols about .8 of a pound.", "overall": 5.0, "summary": "Neat", "unixReviewTime": 1369958400, "reviewTime": "05 31, 2013"}

每个文件都包含这样的数十万行

如何从所有文件中随机获得1000个键reviewText的值? 最终输出将保存在一个文本文件中,每一行将包含一个reviewText

以下是获取包含亚马逊评论的大文件的来源:
http://jmcauley.ucsd.edu/data/amazon/

以上示例来自此文件:
http://snap.stanford.edu/data/amazon/productGraph/categoryFiles/reviews_Tools_and_Home_Improvement_5.json.gz


Tags: and文件ofthetoinmyare