DBF records API
Tim Chase
python.list at tim.thechases.com
Fri Jun 1 18:13:10 EDT 2012
On 06/01/12 15:05, Ethan Furman wrote:
> MRAB wrote:
>> I'd probably think of a record as being more like a dict (or an
>> OrderedDict)
>> with the fields accessed by key:
>>
>> record["name"]
>>
>> but:
>>
>> record.deleted
>
> Record fields are accessible both by key and by attribute -- by key
> primarily for those cases when the field name is in a variable:
>
> for field in ('full_name','nick_name','pet_name'):
> print record[field]
>
> and since dbf record names cannot start with _ and are at most 10
> characters long I've used longer than that method names... but if I want
> to support dbf version 7 that won't work.
It seems to me that, since you provide both the indexing notation
and the dotted notation, just ensure that the methods such as
dbf.scatter_fields
*always* trump and refer to the method. This allows for convenience
of using the .field_name notation for the vast majority of cases,
but ensures that it's still possible for the user (of your API) to
use the indexing method to do things like
value = dbf["scatter_fields"]
if they have a thusly-named field name and want its value.
-tkc
More information about the Python-list
mailing list