2017-11-09 12 views
-2

Python GUIを作成しましたが、今では変数に参照と総コストをファイルに保存したいと思います。
どうすれば実現できますか?以下の結果をPythonでファイルに書き出す方法/結果を保存するには?

enter image description here

は次のようにファイルの書き込みをしようとしたことがあり:

def writetofile(): 
    import os 
    outputname ='tutorial.txt' 
    a= "TotalCost" 

    myfile = open(outputname,'w') 
    myfile.write('File A value is : ' + str(a) + '\n') 
    myfile.close() 

    if os.stat(outputname).st_size > 0: 
     print("tutorial.txt file has been populated") 
    else: 
     print("the output value is empty") 
     print("The A value should read:  " + str(a) + '\n') 

writetofile() 

だけテキストは文字列ではなく、計算されたのですにtotalCost

答えて

0
a= "TotalCost" 

の計算値ではなく、来ています値。

あなたのGUIのコールwritetofile(TotalCost)

を作り、今、この

import os 

def writetofile(total_cost): 

    outputname ='tutorial.txt' 
    a= total_cost # this is a variable you're writing to the file 

をお試しください

関連する問題