Skip to content

Instantly share code, notes, and snippets.

@celisflen-bers
Forked from bertspaan/README.md
Last active March 11, 2022 11:45
Show Gist options
  • Select an option

  • Save celisflen-bers/fe827aa724997b0487a084d225054e2c to your computer and use it in GitHub Desktop.

Select an option

Save celisflen-bers/fe827aa724997b0487a084d225054e2c to your computer and use it in GitHub Desktop.

Revisions

  1. celisflen-bers revised this gist Sep 24, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion dbf2csv.py
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@

    filename = sys.argv[1]
    if filename.endswith('.dbf'):
    print ("Converting %s to csv", filename)
    print ("Converting %s to csv" % filename)
    csv_fn = filename[:-4]+ ".csv"
    with open(csv_fn,'wb') as csvfile:
    in_db = dbf.Dbf(filename)
  2. celisflen-bers revised this gist Sep 24, 2016. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions dbf2csv.py
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@

    filename = sys.argv[1]
    if filename.endswith('.dbf'):
    print "Converting %s to csv" % filename
    print ("Converting %s to csv", filename)
    csv_fn = filename[:-4]+ ".csv"
    with open(csv_fn,'wb') as csvfile:
    in_db = dbf.Dbf(filename)
    @@ -19,6 +19,6 @@
    for rec in in_db:
    out_csv.writerow(rec.fieldData)
    in_db.close()
    print "Done..."
    print ("Done...")
    else:
    print "Filename does not end with .dbf"
    print ("Filename does not end with .dbf")
  3. @bertspaan bertspaan created this gist Jan 2, 2014.
    8 changes: 8 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    # Python script to convert DBF database file to CSV

    - 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
    24 changes: 24 additions & 0 deletions dbf2csv.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #!/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"