![](/img/trans.png)
[英]Python: how to create a new file and write contents of variable to it?
[英]python: How to write variable-contents to a file?
如何將變量內容傳遞給f.write()
函數,以便將變量內容寫入文件?
即將變量jsonData移動到函數f.write()
def get(self):
url = 'http://httpbin.org/get'
r = requests.get(url)
data = r.text
jsonData = json.loads(data)
# #TODO: send jsonData variable to log file.
f = open('test_logs.txt', 'a+')
f.write('jsonData')
f.close()
return jsonData
f.write(str(jsonData))
雖然您可能應該寫入json文件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.