我想将json文件保存为txt文件。我的txt文件应如下所示:
这是我的代码:
# For loop which will add each available tweet to a new line of tweet_json.txt
with open('tweet_json.txt', 'a', encoding='utf8') as f:
for tweet_id in twitter_archive['tweet_id']:
try:
tweet = api.get_status(tweet_id, tweet_mode='extended')
json.dump(tweet._json, f)
f.write('./')
except:
continue
# For loop to append each tweet into a list
tweets_data = []
tweet_file = open('tweet_json.txt', "r")
for line in tweet_file:
try:
tweet = json.loads(line)
tweets_data.append(tweet)
except:
continue
tweet_file.close()
感谢您的帮助!