Neil Cerutti wrote, on Wednesday, June 07, 2017 10:36 AM > > On 2017-06-06, Deborah Swanson <pyt...@deborahswanson.net> wrote: > >> I too have sometimes started with a namedtuple and then found I > >> needed to make changes to the records. I typically abandon > namedtuple > >> at this point, after only one bad experience trying to > work around my > >> choice of container. > > > > I can appreciate that reaction. > > > > Guess I'm a bit of a bulldog though (right ot wrong), and the concept > > of namedtuples is so ideally suited for the Excel spreadsheet > > conversions I'm working on, I'll keep on pushing the boundaries to see > > how they can be made to work. ;) > > The namedtuple has found a happy place in my repertoire as > the return value of functions that transform external > read-only tabular data into a convenient form for lookup. > > I agree pushing a language feature beyond its preferable use > cases is a good way to learn concepts and illuminate dark > corners of both my own skill and Python's features.
I certainly have learned a lot by doing exactly that. Sometimes it isn't so much people giving the solution to a problem, though that's definitely to the good, but the alternate solutions that are proposed can also be highly instructive. > An Excel spreadsheet that represents a table of data is > fairly simple to map onto a Python dict. One nearly codeless > way is to export it from Excel as a csv file and then read it > with csv.DictReader. > > -- > Neil Cerutti csv.DictReader! I didn't know there was one! I've been thinking about how a spreadsheet could be put into a dict, but wasn't quite coming up with a good way. But a csv.DictReader would be perfect, and I imagine the keys would be the column names, which is also perfect. Thanks for the lead on csv.DictReader. I suppose if I'd known one existed it would be easy to find, but when you don't know, and you don't think of it... Deborah -- https://mail.python.org/mailman/listinfo/python-list