Python:仅将新数据附加到文本文件

时间:2018-06-12 02:20:05

标签: python text append

我正在尝试仅将新数据附加到现有的txt文件中。我是Python的新手。我该怎么做?我只想将新数据点追加到最后。感谢

import json 
import requests

s = requests.get('https://www.bitmex.com/api/v1/trade? 
symbol=XBT7D_D95&count=500&reverse=true')
g = requests.get('https://www.bitmex.com/api/v1/trade? 
symbol=XBT7D_U105&count=500&reverse=true')

myfile = open("Automated10595V1.txt", "a")
   for p in g.json():
    if p['side'] == "Sell" or p['side'] == "Buy":
        myfile.write("{},{},{},{}, {}\n".format(p['symbol'], p['timestamp']  [0:10] + " " + p['timestamp'][11:19], p['side'], p['size'], p['price']))
for p in s.json():
    if p['side'] == "Sell" or p['side'] == "Buy": 
        myfile.write("{},{},{},{}, {}\n".format(p['symbol'], p['timestamp'] [0:10] + " " + p['timestamp'][11:19], p['side'], p['size'], p['price']))
myfile.close()

0 个答案:

没有答案