1

我有一个大文件,我在其上实现了图形算法。程序没有问题。但是我必须将输出写入文件。我的输入将是一个数字,输出将是输入节点连接到的所有节点。生成的文件相当大,大约 4-5 页后突然停止。我遇到并使用了该flush()功能,但无济于事。

我的文件写入代码是:

djkpath =(path[i]," -> ",path[i+1], "[weight = ", g.weights[(path[i], path[i+1])],"]")
            #print(path[i] -> path[i+1] [weight = g.weights[(path[i], path[i+1])]])
            finaldjk = " ".join(map(str, djkpath))
            fo.write(finaldjk)
            fo.write('\n')

fo.write('\n')
fo.write("}")
fo.close()
fo.flush()

生成的文件看起来像(我刚刚包含了看起来不完整的文件末尾):

150  ->  75 [weight =  12 ]
75  ->  45 [weight =  25 ]
85  ->  150 [weight =  9 ]
150  ->  55 [weight =  7 ]
55  ->  20 [weight =  17 ]
20  ->  120 [weight =  7 ]
120  ->  43 [weight 
4

0 回答 0