Oct-01-2024, 07:43 PM
deanhystad,
Thank you, finally got to code that works.
Done before I started this thread.
Thank you, finally got to code that works.
from pprint import pprint def get_all_values(obj, level=0): # Not my function """Walk through a dictionary of dicts and lists.""" if type(obj) is dict: for key, value in obj.items(): if type(value) in [dict, list]: print(' ' * level, key, sep='') level = level + 1 get_all_values(value, level) level = level - 1 else: print(' ' * (level), key, ': ', value, sep='') elif type(obj) is list: for i, element in enumerate(obj): if type(element) in [dict, list]: print(' ' * level, i, sep='') level = level + 1 get_all_values(element, level) level = level - 1 else: print(' ' * (level), element, sep='') else: raise ValueError def add(old, new): # function by deanhystad - curbie comment """Add new dictionary to old.""" while True: key, value = next(iter(new.items())) if key in old: old = old[key] else: old[key] = value break new = value dskn = 0 # alpha micro up to 32mb disk number (16 bit logical disk) ufd = ['1,2', '1,2', '1,4', '1,4'] # list for user file directories file = ['BADBLK.SYS', 'AMOSL.DIR', 'AMOSL.INI', 'AMOS32.INI'] # file name blocks = [3, 42, 2, 4] # list for number of full blocks in file active = [500, 400, 300, 200] # list for number of bytes in last block of file link = [1600, 1500, 1400, 1300] # list for link to first block of file dsk = {} # create blank dictionary for i in range(0, 4): # loop through adding files uuu = ufd[i] fff = file[i] bbb = blocks[i] aaa = active[i] lll = link[i] add(dsk, {dskn: {uuu: {fff: {"blocks": bbb, "active": aaa, "link": lll}}}}) get_all_values(dsk)
(Oct-01-2024, 05:17 PM)deanhystad Wrote: But before writing this, make sure you need it. I would start this project by writing the code that loops through the entire disk (the part you are putting off). That code may reveal disks, dictionaries and files in an order that naturally lends itself to making a nested dictionary without much effort.
Done before I started this thread.
[1,2] Link: 127 PW: | | [1,3] Link: 1081 PW: | | [1,4] Link: 2157 PW: | | plus 29 more UFDs ********************************************************* AAA .BAK Blocks: 1 Active: 2 Link: 2156 ABC .LIT Blocks: 19 Active: 60 Link: 2158 ABCLON.LIT Blocks: 29 Active: 373 Link: 2177 ABMAST.LIT Blocks: 17 Active: 370 Link: 2206 ABMON .CMD Blocks: 1 Active: 54 Link: 2223 ABREAD.LIT Blocks: 4 Active: 254 Link: 2224 ABRELI.EXP Blocks: 1 Active: 30 Link: 2228 ABRELI.LIT Blocks: 21 Active: 454 Link: 2229 ABRELI.OVR Blocks: 10 Active: 416 Link: 2250 ABRELI.RKT Blocks: 4 Active: 299 Link: 2260 ABRELI.RTB Blocks: 4 Active: 228 Link: 2264 ABRELI.SYS Blocks: 16 Active: 122 Link: 2268 ABRND .LIT Blocks: 5 Active: 20 Link: 2284 plus 1400 more full file specs distributed among the UFDsNow on to studying your 'add' function to try to figure out where I goofed up.