title: Using Regular Expressions to extract numerical quantities from a file and find the sum
body: <p>I am a beginner and learning python. The problem is that I have to extract numbers from a file (in which numbers can be anywhere. can be multiple times in the same line. some lines may not have numbers and some lines may be new lines) and find their sum. I did know how to solve it, and this was my code</p>
  
  <pre><code>import re
  new=[]
  s=0
  fhand=open("sampledata.txt")
  for line in fhand:
      if re.search('^.+',line):         #to exclude lines which have nothing
          y=re.findall('([0-9]*)',line) #this part is supposed to extract only the
          for i in range(len(y)):       #the numerical part, but it extracts all the words. why?
              try:
                  y[i]=float(y[i])
              except:
                  y[i]=0
          s=s+sum(y)
  print s
  </code></pre>
  
  <p>The code works, but it is not a pythonic way to do it. Why is the ([0-9]*) extracting all the words instead of only numbers?
  What is the pythonic way to do it?</p>