-2

Have made a python GUI and now I want to store the variable say Reference and Total cost in a file.
How can I achieve that?

enter image description here

Have tried writing a file like:

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()

but only the text is coming, not the calculated value of TotalCost

Phantômaxx
  • 36,442
  • 21
  • 78
  • 108
roxy007
  • 1
  • 1

1 Answers1

0
a= "TotalCost"

That's a string, not a calculated value.

Try this

import os

def writetofile(total_cost):

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

Now, make your GUI call writetofile(TotalCost)

OneCricketeer
  • 126,858
  • 14
  • 92
  • 185