使用 dbfpy 读取 .dbf 文件时如何重命名该文件的字段名称?
我正在使用 dbfpy 读取 .dbf
文件,效果很好。但是,我想重命名字段名称,这样当我使用 row.asDict() 读取每一行时,字典键将是我的字段名称,而不是文件中的字段名称。当然,我可以为此编写自己的包装器,但我不想重新发明轮子,以防有一个简单的解决方案(我浏览了源代码,没有看到任何内容,并且不想研究整个过程)逐行源)。谢谢!
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 file. 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从来没有使用过dbfpy,但是使用我写的 package 会是这样的:
然而,这实际上会更改原始 dbf 文件中的名称。
编辑
我记得另一种方式:这种方式实际上不会重命名任何内容,但由于我的 dbf 模块中的记录允许索引以及字段名称访问,您可以执行以下操作:
然后
I have never used dbfpy, but using the package I wrote it would be like this:
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:
and then later