python 读取DBF
时间: 2023-10-17 07:31:11 浏览: 200
dbfread:使用Python读取DBF文件
Python可以使用dbfread库来读取DBF文件。DBF是dBase,Visual FoxPro和FoxBase等数据库使用的文件格式。dbfread库可以读取DBF文件,并将数据作为本机Python数据类型返回,以便进行进一步处理。这个库主要用于批处理作业和一次性脚本。你可以使用以下代码来读取DBF文件:
```
import dbfread
def readDbfFile(filename):
table = dbfread.DBF(filename, encoding='GBK')
for field in table.fields:
print(field)
for record in table:
for field in record:
print(field, record[field])
for delete_record in table.delete:
print(delete_record)
```
以上代码中的`filename`是DBF文件的路径。你可以在`readDbfFile`函数中使用这个路径来读取文件,并打印字段和记录的信息。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [dbfread:使用Python读取DBF文件](https://download.csdn.net/download/weixin_42175776/18676719)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [python读取dbf文件、dbf转xls、入库Postgres](https://blog.csdn.net/qq_41441896/article/details/127219118)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [python读写dbf数据库](https://blog.csdn.net/weixin_33701251/article/details/94542215)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文