def cs_filter(f, filter_, ignore_comment_lines=True):
 exp = '^\\s*#\\s+CS:.*%s.*ignore\\D*((\\d+)\\s+line)*'
 re_ignore = re.compile((exp % filter_))
 ignore = 0
 out = []
 count = 1
 for line in f:
  if (ignore > 0):
   line = ''
   ignore -= 1
  matches = re_ignore.search(line)
  if matches:
   ignore = int((matches.group(2) or 1))
  if (ignore_comment_lines and line.lstrip().startswith('#')):
   line = ''
  out.append(line)
  count += 1
 return out

def cs_filter ( f , filter_ , ignore_comment_lines = True ) : exp = '^\\s*#\\s+CS:.*%s.*ignore\\D*((\\d+)\\s+line)*' re_ignore = re . compile ( ( exp % filter_ ) ) ignore = 0 out = [ ] count = 1 for line in f : if ( ignore > 0 ) : line = '' ignore -= 1 matches = re_ignore . search ( line ) if matches : ignore = int ( ( matches . group ( 2 ) or 1 ) ) if ( ignore_comment_lines and line . lstrip ( ) . startswith ( '#' ) ) : line = '' out . append ( line ) count += 1 return out
filter the file removing comments if requested .