Q:

how to read 2 txt files and write the result in a third file using python

I have 3 files with the following content:
today.txt
570
yesterday.txt
500
now.txt
0
Basically, i need to read the first 2 files and write the result in the third file:
today.txt - yesterday.txt = now.txt (570 - 500 = 70) 

A:

Open file for reading, read the integer, do the math, write back the results
fpToday = open("today.txt", "r")
fpYesterday = open("yesterday.txt","r")
fpNow = open("now.txt","w")
numToday = fpToday.read().rstrip('\n')
numYesterday =fpYesterday.read().rstrip('\n')
numNow = int(numToday) - int(numYesterday)
fpNow.write(str(numNow))
fpToday.close()
fpYesterday.close()
fpNow.close()

