1234567891011121314151617181920212223 |
- def find_nhs_numbers(fn):
- try:
- f = open(fn, 'rb')
- except IOError:
- return None
- locations = []
- num = 0
- while True:
- c = f.read(1)
- if c == '':
- break
- ascii_ = ord(c)
- if ascii_ in (48, 49, 50, 51, 52, 53, 54, 55, 56, 57):
- num += 1
- else:
- if num == 10:
- startLocation = f.tell() - 11
- f.seek(startLocation)
- if validate_nhs_number(f.read(10)):
- locations.append(startLocation)
- num = 0
- return locations
|