Trying to add numbers from a file subtrack them and put them into another file
Question: 
    file = open("byteS-F_FS_U.toff","r")
    f = file.readline()
    s = file.readline()
    file.close()
    f = int(f)
    s = int(s)
    u = s - f
    file = open("bytesS-F_FS_U","w")
    file.write(float(u) + '\n')
    file.close()
    

This is what its says when I run the code :

    
    
    f file.write(float(u) + '\n') TypeError:
    unsupported operand type(s) for +: 'float' and 'str'
    

I am trying to load numbers from a file that gets new numbers every few
seconds. When they're loaded they're subtracted and put into another file. I
am a new python Programmer.


Answer: First, you need to put full path of the file you're trying to open!

With that first thing fixed, I created a loop program which opens the file
every 10 seconds and writes the result to the other file. Exceptions are
handled so if another process is writing in the file while being opened/read
it does not crash. Python 3 syntax.

    
    
    import time
    
    while True:
        try:
            file = open(r"fullpath_to_your_file\byteS-F_FS_U.toff","r")
            f = int(file.readline())
            s = int(file.readline())
            file.close()
        except Exception as e:
            # file is been written to, not enough data, whatever: ignore (but print a message)
            print("read issue "+str(e))
        else:
            u = s - f
            file = open(r"fullpath_to_your_file\bytesS-F_FS_U","w")    # update the file with the new result
            file.write(str(u) + '\n')
            file.close()
        time.sleep(10)  # wait 10 seconds
    

