Python Forum
Accessing nested dictionary values. Plistlib, Python 2.7
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Accessing nested dictionary values. Plistlib, Python 2.7
#31
OMG...
This sounds like you chasing your tail... You have info in a structured file and you will access it in order to create file in order to access it...
Reply
#32
And here is the output of

print_dict(y) # the dictionary attached to SATA info
['_parentDataType'] = 'SPHardwareDataType'
['_timeStamp'] = datetime.datetime(2017, 9, 22, 9, 3, 47)
['_detailLevel'] = -1
['_properties']['optical_media_type']['_order'] = '52'
['_properties']['spsata_portspeed']['_order'] = '34'
['_properties']['size_in_bytes']['_isByteSize'] = True
['_properties']['size_in_bytes']['_order'] = '10'
['_properties']['spsata_socket_type']['_order'] = '120'
['_properties']['writable']['_order'] = '58'
['_properties']['bsd_name']['_order'] = '62'
['_properties']['device_revision']['_order'] = '44'
['_properties']['device_manufacturer']['_order'] = '40'
['_properties']['spsata_physical_interconnect']['_order'] = '36'
['_properties']['spsata_protocol']['_order'] = '100'
['_properties']['spsata_pm_product_name']['_order'] = '4'
['_properties']['spsata_medium_type']['_order'] = '151'
['_properties']['mount_point']['_order'] = '64'
['_properties']['spsata_ncq_depth']['_order'] = '48'
['_properties']['spsata_trim_support']['_order'] = '152'
['_properties']['spsata_bus']['_order'] = '22'
['_properties']['file_system']['_order'] = '60'
['_properties']['spsata_ncq']['_order'] = '47'
['_properties']['spsata_linkwidth']['_order'] = '37'
['_properties']['spsata_pm_vendor_name']['_order'] = '2'
['_properties']['size']['_order'] = '10'
['_properties']['size']['_deprecated'] = True
['_properties']['spsata_negotiatedlinkspeed']['_order'] = '35'
['_properties']['detachable_drive']['_order'] = '59'
['_properties']['spsata_rotational_rate']['_order'] = '150'
['_properties']['free_space_in_bytes']['_isByteSize'] = True
['_properties']['free_space_in_bytes']['_order'] = '12'
['_properties']['spsata_product']['_order'] = '30'
['_properties']['free_space']['_order'] = '12'
['_properties']['free_space']['_deprecated'] = True
['_properties']['spsata_linkspeed']['_order'] = '38'
['_properties']['spsata_revision']['_order'] = '32'
['_properties']['spsata_async_notify']['_order'] = '140'
['_properties']['spsata_name']['_order'] = '20'
['_properties']['spsata_pm_snotification']['_order'] = '10'
['_properties']['removable_media']['_order'] = '56'
['_properties']['spsata_slot_name']['_order'] = '24'
['_properties']['spsata_vendor']['_order'] = '28'
['_properties']['spsata_rom-revision']['_order'] = '26'
['_properties']['disc_burning']['_order'] = '54'
['_properties']['device_model']['_order'] = '42'
['_properties']['spsata_power_off']['_order'] = '130'
['_properties']['spsata_unit_number']['_order'] = '110'
['_properties']['optical_drive_type']['_order'] = '50'
['_properties']['_name']['_order'] = '0'
['_properties']['_name']['_isColumn'] = 'YES'
['_properties']['_name']['_isOutlineColumn'] = 'YES'
['_properties']['spsata_pm_revision']['_order'] = '6'
['_properties']['volumes']['_detailLevel'] = '0'
['_properties']['device_serial']['_detailLevel'] = '0'
['_properties']['device_serial']['_order'] = '46'
['_properties']['spsata_pm_fbs']['_order'] = '8'
['_dataType'] = 'SPSerialATADataType'
['_versionInfo']['com.apple.SystemProfiler.SPSerialATAReporter'] = '2.1.1'
['_SPResponseTime'] = 0.3667070269584656
['_SPCommandLineArguments'][0] = '/usr/sbin/system_profiler'
['_SPCommandLineArguments'][1] = '-nospawn'
['_SPCommandLineArguments'][2] = '-xml'
['_SPCommandLineArguments'][3] = 'SPSerialATADataType'
['_SPCommandLineArguments'][4] = '-detailLevel'
['_SPCommandLineArguments'][5] = 'full'
['_items'][0]['spsata_portspeed'] = '3 Gigabit'
['_items'][0]['spsata_negotiatedlinkspeed'] = '3 Gigabit'
['_items'][0]['_name'] = 'NVidia MCP79 AHCI'
['_items'][0]['spsata_product'] = 'MCP79 AHCI'
['_items'][0]['spsata_physical_interconnect'] = 'SATA'
['_items'][0]['spsata_vendor'] = 'NVidia'
['_items'][0]['spsata_portdescription'] = 'AHCI Version 1.20 Supported'
['_items'][0]['_items'][0]['smart_status'] = 'Failing'
['_items'][0]['_items'][0]['detachable_drive'] = 'no'
['_items'][0]['_items'][0]['spsata_rotational_rate'] = 7200
['_items'][0]['_items'][0]['spsata_ncq_depth'] = '32'
['_items'][0]['_items'][0]['device_model'] = 'ST3500418ASQ                            '
['_items'][0]['_items'][0]['size_in_bytes'] = 500107862016
['_items'][0]['_items'][0]['_name'] = 'ST3500418ASQ'
['_items'][0]['_items'][0]['spsata_ncq'] = 'Yes'
['_items'][0]['_items'][0]['bsd_name'] = 'disk0'
['_items'][0]['_items'][0]['device_revision'] = 'AP24    '
['_items'][0]['_items'][0]['volumes'][0]['size'] = '209,7 MB'
['_items'][0]['_items'][0]['volumes'][0]['iocontent'] = 'EFI'
['_items'][0]['_items'][0]['volumes'][0]['bsd_name'] = 'disk0s1'
['_items'][0]['_items'][0]['volumes'][0]['size_in_bytes'] = 209715200
['_items'][0]['_items'][0]['volumes'][0]['_name'] = 'EFI'
['_items'][0]['_items'][0]['volumes'][1]['mount_point'] = u'/Volumes/*A\u0308U\u0308P\xdfO\u0308-IK9,JMU8HNZ7BGT6FRV54SWX3AQY2'
['_items'][0]['_items'][0]['volumes'][1]['size_in_bytes'] = 499248103424
['_items'][0]['_items'][0]['volumes'][1]['iocontent'] = 'Apple_HFS'
['_items'][0]['_items'][0]['volumes'][1]['free_space'] = '498,8 GB'
['_items'][0]['_items'][0]['volumes'][1]['writable'] = 'yes'
['_items'][0]['_items'][0]['volumes'][1]['bsd_name'] = 'disk0s2'
['_items'][0]['_items'][0]['volumes'][1]['volume_uuid'] = '7E8EFE9A-C246-3382-AEF1-EAF6F4EFFFE8'
['_items'][0]['_items'][0]['volumes'][1]['_name'] = u'*A\u0308U\u0308P\xdfO\u0308-IK9,JMU8HNZ7BGT6FRV54SWX3AQY2'
['_items'][0]['_items'][0]['volumes'][1]['free_space_in_bytes'] = 498799886336
['_items'][0]['_items'][0]['volumes'][1]['file_system'] = 'Journaled HFS+'
['_items'][0]['_items'][0]['volumes'][1]['size'] = '499,25 GB'
['_items'][0]['_items'][0]['volumes'][2]['iocontent'] = 'Apple_Boot'
['_items'][0]['_items'][0]['volumes'][2]['_name'] = 'Recovery HD'
['_items'][0]['_items'][0]['volumes'][2]['bsd_name'] = 'disk0s3'
['_items'][0]['_items'][0]['volumes'][2]['volume_uuid'] = '82E27D91-EFB0-381D-9DC8-8A1A25FEA879'
['_items'][0]['_items'][0]['volumes'][2]['size_in_bytes'] = 650002432
['_items'][0]['_items'][0]['volumes'][2]['size'] = '650 MB'
['_items'][0]['_items'][0]['spsata_medium_type'] = 'Rotational'
['_items'][0]['_items'][0]['device_serial'] = '            5VMASEQK'
['_items'][0]['_items'][0]['removable_media'] = 'no'
['_items'][0]['_items'][0]['partition_map_type'] = 'guid_partition_map_type'
['_items'][0]['_items'][0]['size'] = '500,11 GB'
['_items'][1]['spsata_portspeed'] = '3 Gigabit'
['_items'][1]['spsata_negotiatedlinkspeed'] = '1.5 Gigabit'
['_items'][1]['_name'] = 'NVidia MCP79 AHCI'
['_items'][1]['spsata_product'] = 'MCP79 AHCI'
['_items'][1]['spsata_physical_interconnect'] = 'SATA'
['_items'][1]['spsata_vendor'] = 'NVidia'
['_items'][1]['spsata_portdescription'] = 'AHCI Version 1.20 Supported'
['_items'][1]['_items'][0]['detachable_drive'] = 'no'
['_items'][1]['_items'][0]['device_model'] = 'HL-DT-ST DVDRW  GA11N                   '
['_items'][1]['_items'][0]['spsata_power_off'] = 'No'
['_items'][1]['_items'][0]['_name'] = 'HL-DT-ST DVDRW  GA11N'
['_items'][1]['_items'][0]['spsata_ncq'] = 'No'
['_items'][1]['_items'][0]['spsata_async_notify'] = 'Yes'
['_items'][1]['_items'][0]['device_revision'] = 'JA18    '
['_items'][1]['_items'][0]['device_serial'] = 'KZKA2AD2212         '
['_SPCompletionInterval'] = 0.2432050108909607

Process finished with exit code 0
I'll have to attack this again later this evening when I get back from work... I think a solution is on the horizon
Reply
#33
Well the chasing of the tail has paid off...

Outputting a text file and then re-imporing it was never something I was going to take seriously.

Tried this...

for y in candidates2:
    HDsize = y['_items'][0]['_items'][0]['size']
and magically it gave me back "500,11 GB". It does#t matter how many SATA drives there are.

Thank God for that "print_dict()" function and whereever it came from!!!

Accessing other Apple hardware info in Python is now a breeze. No more blinding feeling through a dict with a 'for' loop.

Thanks buran for at least getting me out of the shadows here.

Edit - link to "print_dict()" function. https://stackoverflow.com/questions/1075...ary-values
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  need to compare 2 values in a nested dictionary jss 2 847 Nov-30-2023, 03:17 PM
Last Post: Pedroski55
  Printing specific values out from a dictionary mcoliver88 6 1,376 Apr-12-2023, 08:10 PM
Last Post: deanhystad
  Accessing same python script from multiple computers bigrockcrasher 1 1,686 May-25-2022, 08:35 PM
Last Post: Gribouillis
  Python modules for accessing the configuration of relevant paths Imago 1 1,365 May-07-2022, 07:28 PM
Last Post: Larz60+
Question How to print each possible permutation in a dictionary that has arrays as values? noahverner1995 2 1,731 Dec-27-2021, 03:43 AM
Last Post: noahverner1995
  plistlib / xml file / get value except key Tecuma 6 3,210 May-26-2021, 03:51 PM
Last Post: Tecuma
  Nested dictionary acting strange Pedroski55 2 2,076 May-13-2021, 10:37 PM
Last Post: Pedroski55
  format the output from a nested dictionary. nostradamus64 9 4,514 May-03-2021, 04:45 PM
Last Post: nostradamus64
Lightbulb Python Nested Dictionary michaelserra 2 2,588 Apr-18-2021, 07:54 AM
Last Post: michaelserra
  Getting values from a dictionary brunolelli 5 3,564 Mar-31-2021, 11:57 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020