How to grab number after word in python

Use regular expressions:

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

Leave a Comment