So a couple issues, if you want to grab every digit don't use '\b\d+\b' as that will only grab digits that are not in front of or behind words. Example: it will get "23 street" -> '23' but if you want to get "23rd street" -> '23' you need to use '\d+\'. Otherwise one of the others commenting is correct, it's because your print lst is outside of the for loop. I would be willing to bet the last line of myfile.txt does not contain any digits that are by themsevles, so it never prints anything. There are a few ways to fix it, I'll show you two ways.
import re
lst = ()
fname = "myfile.txt"
try:
with open(fname, 'r') as fh:
for line in fh:
lst = [int(s) for s in re.findall(r'\d+',line)]
print lst
except IOError:
print "Error reading file!"
This is the easier way and you deal with less code, but if you want all of the objects to live inside one array when you print it, you could do something like this too.
import re
lst = []
fname = "myfile.txt"
try:
with open(fname, 'r') as fh:
for line in fh:
lst.append([int(s) for s in re.findall(r'\b\d+\b',line)])
print lst
except IOError:
print "Error reading file!"
You'll notice on line 2 with this one I turned it into a list instead of a tuple. This is so we can use .append on the list comprehension, and print it afterwards.
lstonly after the loop... so it's really saying the last line ofmyfile.txtdoesn't have any digits.