次のインデックスをファイルに書き込む方法を知りたいです。以下のインデックスは、私が作成した関数から返されます。
myIndex = {'incorporating': {2047: 1}, 'understand': {2396: 1}, 'format-free': {720: 1}, 'function,': {1579: 1, 485: 1, 831: 1}, '411)': {2173: 1}, 'augmented': {1350: 1}}
このようなものが出力ファイルに表示されるようにします。
'incorporating': {2047: 1}
'understand': {2396: 1}
'format-free': {720: 1}
'function,': {1579: 1, 485: 1, 831: 1}, '411)': {2173: 1}
'augmented': {1350: 1}
これは私が行ったコードです。writeLine を使用しようとしましたが、ファイルの出力が台無しになりました。そこで、ピクルスのような他の方法を探しました。
def ToFile(self):
indList = myIndex.constructIndex() # a function to get the index above
filename = "myfile.txt"
outfile = open(filename, 'wb')
pickle.dump(indexList, outfile)
outfile.close()
ファイルを確認しましたが、得たものは次のとおりです。
ssS'incorporating'
p8317
(dp8318
I2047
I1
ssS'understand'
p8319
(dp8320
I2396
I1
ssS'format-free'
p8321
(dp8322
I720
I1
ssS'function,'
p8323
(dp8324
I1579
I1
sI485
I1
sI831
I1
ssS'411)'
p8325
(dp8326
I2173
I1
ssS'augmented'
p8327
(dp8328
I1350
I1
ss.