Python Forum
how to print all data from all data array?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to print all data from all data array?
#1
Hello,
maybe the names is incorrect so I will show in example
x = [{'id': '*1F010121', 'name': 'hotspot/Fonts', 'type': 'directory', 'creation-time': 'may/06/2018 09:35:12'},
{'id': '*1F010221', 'name': 'hotspot/images', 'type': 'directory', 'creation-time': 'may/06/2028 09:35:12'}]
}
I want to print all the names of the directory he found

something like
***** I KNOW THIS IS NOT THE CORRECT COMMAND
foreach data in x:
    print(x["name"][data])
so I will get
hotspot/Fonts , hotspot/images

Thanks ,
Reply
#2
Don;t know how to remove the post

But after playing I have found the answer:
for names in response:
    print(names['name'])
    List_OF_Names.append(names['name'])
Reply
#3
I wrote a generic function to list dictionaries,
main() function shows how to display your data

def display_dict(dictname, level=0):
    indent = " " * (4 * level)
    for key, value in dictname.items():
        if isinstance(value, dict):
            print(f'\n{indent}{key}')
            level += 1
            self.display_dict(value, level)
        else:
            print(f'{indent}{key}: {value}')
        if level > 0:
            level -= 1


def main():
    x = [{'id': '*1F010121', 'name': 'hotspot/Fonts', 'type': 'directory', 'creation-time': 'may/06/2018 09:35:12'},
        {'id': '*1F010221', 'name': 'hotspot/images', 'type': 'directory', 'creation-time': 'may/06/2028 09:35:12'}]
    for item in x:
        print(display_dict(item))


if __name__ == '__main__':
    main()
Output:
id: *1F010121 name: hotspot/Fonts type: directory creation-time: may/06/2018 09:35:12 None id: *1F010221 name: hotspot/images type: directory creation-time: may/06/2028 09:35:12 None
Reply
#4
nice solution
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python: How to import data from txt, instead of running the data from the code? Melcu54 1 656 Dec-13-2024, 06:50 AM
Last Post: Gribouillis
  JSON File - extract only the data in a nested array for CSV file shwfgd 2 1,089 Aug-26-2024, 10:14 PM
Last Post: shwfgd
  XML minidom "Pretty Print" Lost Data marksy95 2 1,251 Jun-15-2024, 11:09 AM
Last Post: Larz60+
  Help with to check an Input list data with a data read from an external source sacharyya 3 1,688 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  print(data) is suddenly invalid syntax db042190 6 3,230 Jun-14-2023, 02:55 PM
Last Post: deanhystad
  Write sql data or CSV Data into parquet file mg24 2 4,170 Sep-26-2022, 08:21 AM
Last Post: ibreeden
  Load multiple Jason data in one Data Frame vijays3 6 2,769 Aug-12-2022, 05:17 PM
Last Post: vijays3
  Issue in changing data format (2 bytes) into a 16 bit data. GiggsB 11 5,045 Jul-25-2022, 03:19 PM
Last Post: deanhystad
  Seeing al the data in a dataframe or numpy.array Led_Zeppelin 1 1,735 Jul-11-2022, 08:54 PM
Last Post: Larz60+
Question Change elements of array based on position of input data Cola_Reb 6 3,485 May-13-2022, 12:57 PM
Last Post: Cola_Reb

Forum Jump:

User Panel Messages

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