On 31Mar2020 22:28, Nadav Wexler <[email protected]> wrote:
that's what I assumed...
thanks for the reply! :)

Also, there are modules to provide this kind of thing when you want it.

For example, my cs.mappings module:

 https://pypi.org/project/cs.mappings/

has dicts_to_namedtuples() which converts an iterable of dicts to namedtuples, and the lower level function named_row_tuple(*keys) function used to create the specific namedtuple class from some keys (eg your_dict.keys()). There's also named_column_tuples() which presumes the column/attribute names come from the first data row.

I wrote these when processing some data received as a spreadsheet, whose column names (from the human typed header row) tended to be stable, but the number and ordering of the columns were undependable. Feeding them through these (via an additional layer in cs.csvutils) got me nice tuples with readable attribute names.

I'm sure there must be other modules with similar facilities as well.

Cheers,
Cameron Simpson <[email protected]>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/UMGJQPP5J44NX5FQNIOUWRTORCIISRVU/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to