def METHOD_NAME(cls, filename):
    segsel = cls()
    segfile = open(filename, 'rt')
    for line in segfile:
        wline = line.strip()
        if wline[0] == '#' or wline == '':
            continue
        fields = re_split_segspec.split(wline)
        if len(fields) != 2:
            raise ValueError('malformed segment selection {!r}'.format(line))
        try:
            n_iter, seg_id = list(map(int, fields))
        except ValueError:
            raise ValueError('malformed segment selection {!r}'.format(line))
        segsel.add((n_iter, seg_id))
    return segsel