- First download
dbfpy: http://sourceforge.net/projects/dbfpy/files/latest/download?source=files - Then install:
sudo python setup.py install
To convert DBF file to CSV:
./dbf2csv database.dbf
dbfpy: http://sourceforge.net/projects/dbfpy/files/latest/download?source=filessudo python setup.py installTo convert DBF file to CSV:
./dbf2csv database.dbf
| #!/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") |
Some steps to try on Mac, can use it in Windows or Linux but I had not tested on them
$ python -m pip install dbfpy
$ cd /folder/to/have/both/files
$ python dbf2csv.py database.dbf
Works like a charm!
The tip is to have python 2, and pip installed
After downloading the exe and running the code provided, I'm getting the following error:
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\site-packages\dbfpy\dbf.py", line 280
print repr(_rec)
^
SyntaxError: invalid syntax
Am I using the right version of Python?
You saved my bacon with this, Thank you!
Fellas, I ve been having issues with slots from fields.py as I try to run the code:
import fields
File "C:\Users\Amore\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\dbfpy\fields.py", line 44, in <module>
class DbfFieldDef(object):
ValueError: 'length' in __slots__ conflicts with class variable
Any thoughts on how to solve it?
Cheers
Hello, any hint on how to make this run in Windows 10?,