On 06/06/17 13:29, Neil Cerutti wrote:
On 2017-06-06, Deborah Swanson <pyt...@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 to 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.
--
https://mail.python.org/mailman/listinfo/python-list