Corrected iterator errors
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function
-import os
+import os,re
import numpy as np
import utilities.misc_io as util
@@ -44,10 +44,20 @@ class KeywordsMatching(object):
return new_matcher
def matching_subjects_and_filenames(self):
+ list_final = []
+ name_list_final = []
+ for p in self.list_paths:
+ for filename in os.listdir(p):
+ if any(c not in filename for c in self.list_contain):
+ continue
+ if any(c in filename for c in self.list_not_contain):
+ continue
+ full_file_name = os.path.join(p, filename)
+ list_final.append(full_file_name)
+ name_list_final.append(self.extract_subject_id_from(filename))
path_file=[(p,filename) for p in self.list_paths for filename in os.listdir(p)]
- func_match = lambda x: all(c in x[1] for c in self.list_contain) and
- not any(c in x[1] for c in self.list_not_contain)
- matching_path_file=filter(func_match,path_file)
+ func_match = lambda x: all(c in x[1] for c in self.list_contain) and not any(c in x[1] for c in self.list_not_contain)
+ matching_path_file=list(filter(func_match,path_file))
list_final=[os.path.join(p,filename) for p,filename in matching_path_file]
name_list_final=[self.extract_subject_id_from(filename) for p,filename in matching_path_file]
return list_final, name_list_final
@@ -58,6 +68,6 @@ class KeywordsMatching(object):
noncapturing_regex_delimiters=['(?:'+re.escape(c)+')' for c in self.list_contain]
potential_names=re.split('|'.join(noncapturing_regex_delimiters),name)
# filter out non-alphanumeric characters and blank strings
- potential_names=[re.sub(r'\W+', '', name) for name in potential_names)
+ potential_names=[re.sub(r'\W+', '', name) for name in potential_names]
potential_names=[name for name in potential_names if name is not '']
return potential_names
\ No newline at end of file
