Joe Joe - 1 year ago 58
Python Question

Prevent dict from creating in list

I am trying to create a dictionary from an xlsx file. Here is the code:

import pyexcel as pe

records = pe.get_records(file_name="testxl.xlsx")

This is creating the dict but stuffing it inside a list. First, how do I stop it from actually creating the dict inside the list? Second, Why is it doing this? Is it better for some reason? I have read the posts on here about accessing data through the list, I just do not see the point of having it at all.

Answer Source

Looking into the pyexcel API documentation, the get_records function loads the excel file line by line, providing a list of dictionaries with column headers as keys and field entries as values. If you happened to work with CSV (comma-separated-value) APIs - they tend to work the same way. It's simply the most straight-forward way to retrieve the tabular data.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download