I am very new to Python, but with experience in other languages.
My problem arises when trying to use a module to read DBF files; and that I still do not assimilate the Python data structures.
The example of use that this module brings is:
from dbfread import DBF for record in DBF ('people.dbf'): print (record)
OrderedDict ([('NAME', 'Alice'), ('BIRTHDATE', datetime.date(1987, 3, 1))]) OrderedDict ([('NAME', 'Bob'), ('BIRTHDATE', datetime.date(1980, 11, 12))])
Where NAME and BIRTHDATE, are the field names of 'people.dbf'.
'Alice' and datetime.date (1987, 3, 1) are the values of those fields, in the first record.
My problem is that I do not know how to reference these values so that, in each iteration, I assign them to variables.
I mean, something like …
name = record.OrderedDict ('NAME') # that the variable name is assigned 'Alice' date = record.OrderedDict ('BIRTHDATE') # that the date variable assigns datetime.date (1987, 3, 1)
The module loads a single record for each iteration. That is, it does not load all the records in a structure that can then be traversed.
Only the last record read is available in each iteration.