Sep-29-2017, 05:03 AM
(This post was last modified: Sep-29-2017, 05:09 AM by williamlombard.)
I think I may have found some hackish way around this problem....
I found a "print_dict" function online on another forum last night.
I know the xml/plist data is no fun to read but I'm certain there is an easier way of getting access to this info?
I found a "print_dict" function online on another forum last night.
def print_dict(v, prefix=''): if isinstance(v, dict): for k, v2 in v.items(): p2 = "{}['{}']".format(prefix, k) print_dict(v2, p2) elif isinstance(v, list): for i, v2 in enumerate(v): p2 = "{}[{}]".format(prefix, i) print_dict(v2, p2) else: print('{} = {}'.format(prefix, repr(v)))
for y in candidates2: for item in y['_items']: for item2 in item['_items']: HDDetails = print_dict(item2)the console outputs
['smart_status'] = 'Failing' ['detachable_drive'] = 'no' ['spsata_rotational_rate'] = 7200 ['spsata_ncq_depth'] = '32' ['device_model'] = 'ST3500418ASQ ' ['size_in_bytes'] = 500107862016 ['_name'] = 'ST3500418ASQ' ... and so onI can try saving the console output to a text file using sys.stdout and then later in the same script (outside the for loop) reopening the file and using string methods to chop it up and get the hard drive information I need.
I know the xml/plist data is no fun to read but I'm certain there is an easier way of getting access to this info?