Created
March 30, 2016 21:21
-
-
Save vmanyushin/57841023fb4cbe76ad922302d7007315 to your computer and use it in GitHub Desktop.
Convert dbf to csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import csv | |
from dbfpy import dbf | |
import os | |
import sys | |
filename = sys.argv[1] | |
if filename.endswith('.dbf'): | |
print "Converting %s to csv" % filename | |
csv_fn = filename[:-4]+ ".csv" | |
with open(csv_fn,'wb') as csvfile: | |
in_db = dbf.Dbf(filename) | |
out_csv = csv.writer(csvfile) | |
names = [] | |
for field in in_db.header.fields: | |
names.append(field.name) | |
out_csv.writerow(names) | |
for rec in in_db: | |
out_csv.writerow(rec.fieldData) | |
in_db.close() | |
print "Done..." | |
else: | |
print "Filename does not end with .dbf" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
taking this from https://gist.github.com/bertspaan/8220892