Python操作dbf文件
pip install dbf
pip install dbf
'''
用于读取/写入 dBase、FoxPro 和 Visual FoxPro .dbf 文件(包括备忘录)的纯 python 包
'''
环境
- Python 3.9.5
- dbf 0.99.2
如何读取、修改、保存dbf文件
import dbf
# 读取dbf文件, with 语句会自动关闭文件
with dbf.Table('test.dbf') as table:
for record in table:
print(record) # 打印每一行
# 修改dbf文件
with dbf.Table('test.dbf') as table:
for r in dbf.Process(table)
r['name'] = 'new name'
r[3] = 200
# with 语句会自动保存文件
中文支持
import dbf
# 简体中文
dbf.Table(filename, codepage='cp936')
# 繁体中文
dbf.Table(filename, codepage='cp950')
引用
https://www.github.com/ethanfurman/dbf