python - How can I convert parent - child relationship into a dictionary? -


the code far is:

for root, dirs, files in os.walk(path):     directory in dirs:         if directory.endswith("gui"): # folders end gui             print "parent is: ", (os.path.join(root, directory))             os.chdir(os.path.join(root, directory))             file in glob.glob("*.b"): # files end b                   print "child is: ", (file)                   dictionaryparentchild[directory] = file return dictionaryparentchild 

current: code return 1 parent: 1 child desired: code should return 1 parent: many children

def dir_files_map(start_dir):     import os     dd = {}     # create dictionary key folder root path     # , values files in folder     # filter files based on endswiths(string) clause     root, subfolders, filenames in os.walk(start_dir):         f in filenames:             if f.endswith('.b'):                dd.setdefault(root,[]).append(f)     return dd 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -