简体   繁体   中英

convert dbf to csv without MS excel

在不使用win32com.client或其他依赖于微软软件的软件包的情况下,将 .dbf 文件转换为 .csv 文件的最佳方法(最低计算成本)是什么?

You can read dBase files using the dbf package . The package includes support for writing tables to CSV directly, or you could write your own with the The Writer class from the csv standard library module if you need more control.

Being pure Python it may not be the fastest solution available, but it should be portable.

Lately I've been using the following code for quick and dirty csv to dbf conversions, primary in the context of preparing csv files for import into ArcGIS file geodatabases. The code uses the dbf package .

import dbf, os
def csv_to_dbf(inCSV,outDBF):
    outFile = open(<temporary CSV>),'w')
    with open(inCSV,'r') as f:
        count = 0
        for line in f:
            if count == 0: header = line.rstrip("\n").split(",")
            else: outFile.write(line)
            count +=1    
    dbf.from_csv(csvfile=<temporary CSV>, field_names=header, filename= outDBF ,to_disk=True)
    os.remove(<temporary CSV>)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM