python: 如何将变量内容写入文件?

python: How to write variable-contents to a file?

如何将变量内容传递给 f.write() 函数,以便将变量内容写入文件?

i.e. move variable jsonData to function 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 文件