def clean_config(config, patterns):
 comment_out_list = []
 for line in config:
  if line.strip().startswith('#'):
   continue
  if ('#' in line):
   pure_line = line[:line.index('#')]
  else:
   pure_line = line
  if pure_line.strip().endswith(','):
   comment_out_list.append(line)
   continue
  if any([re.search(pat, pure_line) for pat in patterns]):
   comment_out_list.append(line)
 new_config = [(line if (line not in comment_out_list) else ('#' + line)) for line in config]
 return new_config

def clean_config ( config , patterns ) : comment_out_list = [ ] for line in config : if line . strip ( ) . startswith ( '#' ) : continue if ( '#' in line ) : pure_line = line [ : line . index ( '#' ) ] else : pure_line = line if pure_line . strip ( ) . endswith ( ',' ) : comment_out_list . append ( line ) continue if any ( [ re . search ( pat , pure_line ) for pat in patterns ] ) : comment_out_list . append ( line ) new_config = [ ( line if ( line not in comment_out_list ) else ( '#' + line ) ) for line in config ] return new_config
reads the users config file and comments out lines that are problematic .