Namedtuple problem #32.11.d

Deborah Swanson python at deborahswanson.net
Tue Jun 6 16:27:33 EDT 2017


Richard Moseley wrote, on Tuesday, June 06, 2017 8:16 AM
> 
> On 06/06/17 13:29, Neil Cerutti wrote:
> > On 2017-06-06, Deborah Swanson <python at deborahswanson.net> wrote:
> >> I have a list of namedtuples:
> >>
> >> 	[{Record}(r0=v0, r1=v1,...,r10=v10,r11='',...r93='')
> >> 		. . .
> >>   	{Record}(r0=v0, r1=v1,...,r10=v10,r11='',...r93='')]
> >>
> >> In the first section of code, I process some of the first 10
columns 
> >> (r0=v0, r1=v1,...,r10=v10), and place the results in blank columns,

> >> also in the first 10 columns.
> > 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.

> In a package that I'm working on that enables access natively legacy 
> C-ISAM files, I've found that I need to create a form of a namedtuple 
> that makes use of descriptors to access each of the fields within a 
> record using attribute lookup, but to also create the record object at

> runtime using a description of the fields read from another file
(C-ISAM 
> works by using offsets within a record and does not natively store a 
> mapping between name and offset). I found that using a metaclass to 
> store the fields in a OrderedDict enabled me to embed a namedtuple to 
> return the record back to the rest of the package. The code can be
found 
> in pyisam/table/record.py from 
> http://github.com/rpmoseley/pyisam.git. 
> The code is written for 3.x but the code path for versions before 3.6 
> should work for 2.7.

Since I frequently want to work across columns and down rows, sometimes
as a step in an overall process, your metaclass sounds like an
incredible solution for those sections I need this capability for.

However, in my online course studies to date, they only covered classes
for two weeks, the last week of which was spent on inheritance. So
needless to say, my experience with classes is of the simplest kind, and
I'd never heard of metclasses before I started reading this list.

But rest assured, the functionality you describe is so potentially
useful to me that I will learn what I need to know to understand your
metaclass. But this will take some time, and I may not get to it
immediately, though I'm saving your message so I can get to it at the
first possible chance.

Thank you for letting me know about this solution, which I will remember
and I look forward to learning how to use it.

Deborah




More information about the Python-list mailing list