title: Sum of strings extracted from text file using regex
body: <p>I am just learning python and need some help for my class assignment. </p>
  
  <p>I have a file with text and numbers in it. Some lines have from one to three numbers and others have no numbers at all.</p>
  
  <p>I need to:</p>
  
  <ol>
  <li><p>Extract numbers only from the file using regex</p></li>
  <li><p>Find the sum of all the numbers</p></li>
  </ol>
  
  <p>I used regex to extract out all the numbers. I am trying to get the total sum of all the numbers but I am just getting the sum of each line that had numbers.  I have been battling with different ways to do this assignment and this is the closest I have gotten to getting it right. </p>
  
  <p>I know I am missing some key parts but I am not sure what I am doing wrong. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>import re
  text = open('text_numbers.txt')
  
  for line in text:
      line = line.strip()
      y = re.findall('([0-9]+)',line)
  
      if len(y) &gt; 0:
          print sum(map(int, y))
  </code></pre>
  
  <p>The result I get is something like this 
  (each is a sum of a line):</p>
  
  <blockquote>
    <p>14151</p>
    
    <p>8107</p>
    
    <p>16997</p>
    
    <p>18305</p>
    
    <p>3866</p>
  </blockquote>
  
  <p>And it needs to be one sum like this (sum of all numbers):</p>
  
  <blockquote>
    <p>134058</p>
  </blockquote>