开发者

How can I rename the field names of a .dbf file when reading it with dbfpy?

I am using dbfpy to read from a .dbf file, which works great. However, I want to rename the field names, such that when I read each row using row.asDict(), the dict keys will be my field names and not the ones from the fi开发者_开发问答le. I can write my own wrapper for this, of course, but I didn't want to reinvent the wheel in case there is an easy solution (I skimmed the source, didn't see anything, and didn't want to study the whole source line by line). Thanks!


I have never used dbfpy, but using the package I wrote it would be like this:

import dbf
some_table = dbf.Table('dbf_file')
some_table.rename_field('oldname', 'newname')

This will, however, actually change the name in the original dbf file.

Edit

I remembered another way: this way doesn't actually rename anything, but since records from my dbf module allow indexing as well as field name access you could do something like:

NEW_FIELD = 5    # if the sixth field is the one with the objectionable name

and then later

record[NEW_FIELD] = 'whatever'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜