Python将问题而不是字符串写入文件

时间:2019-03-26 05:58:36

标签: python writetofile

我想将数据从API写入文件,但是我将奇怪的字符写入文件而不是字符串

import requests
end_url = url `+ "?key=" + api_key + "&lang=en-ru" + "&text=" + "Hello 
world"
response = requests.get(end_url)   
str = response.json()["text"][0]   
print(type(str)) # class 'str'   
print(str) # string that i want to write to file   
file = open("translate.txt", 'r+')   
file.write(str)

它应该将我从API获取的字符串写到文件中,但是它是这样写的: �����

0 个答案:

没有答案