Converting a .dbf file to a CSV file

John Machin sjmachin at lexicon.net
Thu Nov 2 15:55:10 EST 2006


Johanna Pfalz wrote:
> Is there a module/method in python to convert a file from .DBF format to
> .CSV format?
>
>

Hi Johanna, the best start at the moment is the Python Cookbook recipe
that others have quoted. Steps:

(1) Input: as per recipe. Note that the recipe handles only the
earliest simplest form of dbf files; you may have data types other than
C, N, D and L. Note that there are myriads of third-party dbf writing
codes out there, and some of them are a little idiosyncratic. I am in
the pre-alpha stage of producing a module whose intent is to read just
about everything it is given, with lots of assertions, error checks,
and warnings. This includes M (memo) fields which are stored in a
separate file in 1 of at least 3 formats. If your file causes the
recipe to crashes or produce incorrect results, there is a good chance
that I may be able to help you.
(2) [optional] derive output file headings from names of fields.
(3) Convert data values to str, if str(input_value) is not appropriate
(4) Write values to csv file. For this I strongly suggest that you use
the Python csv module, rather than attempting to reinvent the wheel
(and the often-forgotten axle). If, as I guess from your name, that you
want the delimiter to be ";" instead of ",", then that can be handled
easily with ..., delimiter=";" in the call to csv.writer.

HTH,
John




More information about the Python-list mailing list