title: reading last line of txt file in python and change it into variable to make calculation
body: <pre><code>td = 'date of transaction.txt'
  tf = 'current balance.txt'
  tr = 'transaction record.txt'
  for line in open(tf):pass
  for line2 in open(td):pass
  for line3 in open(tr):pass
  print line2,line,line3
  """
  so call recall back last record
  """
  rd=raw_input('\ndate of transaction: ')
  print "Choose a type of transaction to proceed... \n\tA.Withdrawal \n\tB.Deposit \n\tC.Cancel &amp; exit"
  slc=raw_input('type of transaction: ')
  i=1
  while (i&gt;0):
      if slc=="A" or slc=="B" or slc=="C":
      i=0
  else:
      i=i+1
      slc=raw_input('invalid selection, please choose again...(A/B/C): ')
  if slc=="A":
      rr=input('\namount of transaction: ')
      Line_len = 10 # or however long a line is, since in my example they all looked the same
      SEEK_END = 2
      file = open(tf, "r")
      file.seek(-Line_len, SEEK_END)
      a = int(str(file.read(Line_len)).split(" ")[0].strip())
      rf=a-rr
      f1=open(tf, 'a+')
      f1.write('\n'+rf)
      f1.close()
      d1=open(td, 'a+')
      d1.write('\n'+rd)
      d1.close
      r1=open(tr, 'a+')
      r1.write('\n-'+rr)
      r1.close
  else:
      print 'later'
  </code></pre>
  
  <p>above is my code, the function is to get data(last line) from txt file and read it, get new data and write it to the txt file again by creating new line.
  my txt file(current balance.txt) should look like this:</p>
  
  <pre><code>2894.00
  2694.00
  </code></pre>
  
  <p>but when i try to use the last line which is 2694.00 to do calculation(rf=a-rr), it failed returning this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Python27\acc.py", line 27, in &lt;module&gt;
      file.seek(-Line_len, SEEK_END)
  IOError: [Errno 22] Invalid argument
  </code></pre>
  
  <p>else if i use this code:</p>
  
  <pre><code>for line in open(tf):
      pass
  a = line
  rf=a-rr
  </code></pre>
  
  <p>it return this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Python27\acc.py", line 27, in &lt;module&gt;
      rf=a-rr
  TypeError: unsupported operand type(s) for -: 'str' and 'int'
  </code></pre>
  
  <p>I seriously have no idea why...please help me...</p>