jeudi 26 février 2015

How to force glob library to read over the files in alfabetical order for each name file?


Vote count:

0




I have this little function that apply a regex to a set of documents over a directory:



def retrive(directory, a_regex):
for filename in glob.glob(os.path.join(directory, '*.txt')):
with open(filename, 'r') as file:
important_stuff = re.findall(a_regex, file.read(), re.S)
my_list = [tuple([j.split()[0] for j in i]) for i in important_stuff]
# print my_list # old line
print str(my_list).strip('[]') + filename.split('/')[-1]


lists_per_file = retrive(directory,regex_)


How can I "guarantee" or "force" retrive function to do its work in an alphabetical aproach (i.e. to apply the regex in alfabetical order for each file name). Thanks in advance guys!



asked 44 secs ago







How to force glob library to read over the files in alfabetical order for each name file?

Aucun commentaire:

Enregistrer un commentaire