Back

Python 操作 dbf 文件

Python 操作 dbf 文件 Python operates on dbf files,用于读取/写入 dBase、FoxPro 和 Visual FoxPro .dbf 文件(包括备忘录)的纯 python 包

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

stackoverflow.com/questions/209840/convert-dbfs-to-csvs

https://pypi.org/project/dbf/

Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy
© Licensed Under CC BY-NC-SA 4.0