title: How to find sum of numbers from a file using a while loop?
body: <p>I am trying to write a function that takes a file name as an argument, and returns the sum of the numbers in the file. Here is what I have done so far:</p>
  
  <pre><code>def sum_digits (filename):
      """
      &gt;&gt;&gt; sum_digits("digits.txt")
      434
      """
      myfile = open(filename, "r")
      newfile = myfile.read()
      sum = 0
      while newfile.isdigit():
          sum += newfile%10
          newfile = newfile/10
      return sum
  
  if __name__=="__main__":
      import doctest
      doctest.testmod(verbose=True)
  </code></pre>
  
  <p>But this code is not working. I dont know how to do this. Any ideas?</p>