def select_residues(fhandle, residue_range):
    """Outputs residues within a certain numbering range.
    """
    prev_res = None
    records = 'ATOM', 'HETATM', 'TER', 'ANISOU'
    for line in fhandle:
        if line.startswith(records):
            res_id = line[21:26]
            if res_id != prev_res:
                prev_res = res_id
            if int(line[22:26]) not in residue_range:
                continue
        yield line
