制作了一个python GUI,现在我想将变量称为参考和总成本存储在一个文件中 我怎样才能做到这一点?
尝试过编写如下文件:
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 :(得分:0)
a= "TotalCost"
这是一个字符串,而不是计算值。
试试这个
import os
def writetofile(total_cost):
outputname ='tutorial.txt'
a= total_cost # this is a variable you're writing to the file
现在,进行GUI调用writetofile(TotalCost)