寫入

def writeDict(writeDict):
    with open("./crypto_backtrader-master/news.txt", "w+") as output:
        output.write(str(writeDict))

讀取

import ast

def readDict():
    with open("./crypto_backtrader-master/news.txt", "r") as data:
        dictionary = ast.literal_eval(data.read())
        return dictionary

呼叫

buyDict={}
buyDict=readDict()

buyDict={}
buyDict['BTC'] = '456'
buyDict['ETH'] = '789'
writeDict(buyDict)

Python更多文章


Python 檢查dict是否有這個key



[教學] Line Bot 機器人不求人 – 範例 (Python)



Python – Selenium 繞過”這個瀏覽器或應用程式可能有安全疑慮”



python 各種均線 10MA/20MA均線 | pandas安裝



python sleep 暫停幾秒執行 – 2021年



PyAutoGUI Python控制電腦 | 按鍵精靈 | 鍵盤控制



python binance币安利用ccxt完成虛擬貨幣自動化交易



python write dictionary to text file | dict 寫入讀取

Categorized in:

Tagged in:

, , , , ,