with open('user_details.txt') as f:
for line in f:
if "bob" in line:
print(line.split()[2])
If you want a list of all nums where bob is in the line use a list comprehension:
with open('user_details.txt') as f:
nums = [line.split()[2] for line in f if "bob" in line]
You may also want to split before you check if you want to avoid cases where the name is a substring of a string in the line, for example bob in bobbing
-> True:
nums = [line.split()[2] for line in f if "bob" in line.split()]
I think a more useful structure would be a dict where the values are all the third numbers in a line associated with each name:
from collections import defaultdict
d = defaultdict(list)
with open("in.txt") as f:
for line in f:
if line.strip():
spl = line.rstrip().split()
d[spl[-1]].append(spl[2])
print(d)
defaultdict(<type 'list'>, {'bob': ['60'], 'dan': ['59']})