How to grab number after word in python

Solution 1:

Use regular expressions:

import re
for line in open('m.txt'):
    match = re.search('uniprotkb:P(\d+)', line)
    if match:
        print match.group(1)

Solution 2:

import re
regex = re.compile('uniprotkb:P([0-9]*)')
print regex.findall(string)