一、json方式
1、字典写入txt
import json
index_list = ['gr_user_katalk', 'gr_group_fb', 'gr_rela_ins', 'gr_group_tg', 'gr_user_tiktok', 'gr_user_tg', 'keyword_all', 'gr_tw_tweets', 'gr_user_ytb', 'gr_user_ins', 'fb_group_user', 'gr_user_fb', 'gr_rela_fb', 'gr_user_wb', 'gr_user_tw', 'gr_message_ptt']
index_dict = {
}
for i in index_list:
index_dict[i] = '2020-12-24T00:00:00.000Z'
print(index_dict)
js = json.dumps(index_dict)
file = open('index_time_dict.txt', 'w')
file.write(js)
file.close()
2、读取txt中的字典
import json
file = open('index_time_dict.txt', 'r')
js = file.read()
index_time_dict = json.loads(js)
file.close()
for i in index_time_dict:
print(i)
print(index_time_dict[i])