python中request获取数据保存到文件

例子如下

aaa = json.loads(response.text)
if aaa['data']['Word8'] != []:
#print(num)
txt = aaa['data']['Word8']
#print(txt)
# open
f = open('word8.txt','a+')
f.write(str(txt)+"\n")
f.close()
if aaa['data']['Word2'] != []:
txt2 = aaa['data']['Word2']
f = open('word2.txt','a+')
f.write(str(txt2)+"\n")
f.close()