0
私がやりたい何ネストされたDictsは、Python 3
Trade 14: 10000.0 (10000.0) of EUR_USD @ 1.07139
Trade 15: 10000.0 (10000.0) of AUD_USD @ 0.76
================================================
Trade ID = 14
Instrument = EUR_USD
Fill Price = 1.07139
Open Time = 2017-01-23T13:12:00.587829255Z
State = OPEN
Initial Trade Units = 10000.0
Current Open Trade Units = 10000.0
Realized Profit/Loss = 0.0
Unrealized Profit/Loss = -205.45
Financing = -8.4385
Trade ID = 15
Instrument = AUD_USD
Fill Price = 76.00
Open Time = 2017-01-23T13:12:00.587829255Z
State = OPEN
Initial Trade Units = 10000.0
Current Open Trade Units = 10000.0
Realized Profit/Loss = 0.0
Unrealized Profit/Loss = -105.45
Financing = -4.4385
を読み込むテキストファイル(traders.txt)を持っているが1つの、各段落から作成された相互にネストされた辞書、およびネストされた辞書を作成することです楽器から標識される
IE newdict['AUD_USD']['Trade ID'] to return 15
and newdict['EUR_USD']['State'] to return OPEN
は、これまでのところ私は必要とされていない最初の数行を落としているが、私はdictionarysを分離する方法がわからない
myfile = open('traders.txt', 'r')
newDict = {}
for line in myfile:
if line in ['\n','\r\n']:
break
for line in myfile:
with open("tradersddd.txt", "a") as fout:
fout.writelines(line)
listedline = line.strip().split('=') # split around the = sign
if len(listedline) > 1:
newDict[listedline[0].strip()] = listedline[1].strip()
print(newDict)
素晴らしいです!コメント/説明もありがとうございます。非常に高く評価。 – kastin