Note that there are some explanatory texts on larger screens.

plurals
  1. POError when trying to convert dbf to csv in Python
    primarykey
    data
    text
    <p>Python newbie here so please be gentle.</p> <p>I'm trying to convert dbf file to csv. I stumbled upon a <a href="https://stackoverflow.com/questions/4440791/convert-csv-file-into-dbf-using-python">previous, similar</a> question (with opposite conversion though) and was thinking abou using <a href="http://pypi.python.org/pypi/dbf/" rel="nofollow noreferrer">dbf</a> module. </p> <p>Using example from the <a href="http://packages.python.org/dbf/" rel="nofollow noreferrer">docs</a> I tried this code:</p> <pre><code>import dbf dbf_fn = r'_PATH_HERE_\dbffile.dbf' csv_fn = r'_PATH_HERE_\csvfile.csv' in_db = dbf.Table(dbf_fn) in_db.export(filename=csv_fn, header=True) </code></pre> <p>When I try to run it I get the following error:</p> <pre><code>Traceback (most recent call last): File "&lt;pyshell#24&gt;", line 1, in &lt;module&gt; in_db.export(filename=csv_fn, header=True) File "C:\Python27\ArcGIS10.1\lib\site-packages\dbf.py", line 3379, in __getattr__ return object.__getattribute__(self, name) AttributeError: 'Db3Table' object has no attribute 'export' </code></pre> <p>Why does the export fail?</p> <hr> <p><strong>Update:</strong></p> <p>As suggested by <a href="https://stackoverflow.com/users/1292791/chm">chm</a> I now use:</p> <pre><code>dbf.export(in_db, csv_fn, header=True) </code></pre> <p>This still causes problem:</p> <pre><code>Traceback (most recent call last): File "D:\Data_RP\data\projects\kN\GIS\python\04_convert_dbf_ALT.py", line 31, in &lt;module&gt; dbf.export(in_db, filename=csv_fn, header=True) File "C:\Python27\ArcGIS10.1\lib\site-packages\dbf.py", line 5670, in export table = source_table(table_or_records[0]) File "C:\Python27\ArcGIS10.1\lib\site-packages\dbf.py", line 3384, in __getitem__ return self._table[value] File "C:\Python27\ArcGIS10.1\lib\site-packages\dbf.py", line 3175, in __getitem__ raise DbfError("%s is closed; record %d is unavailable" % (meta.filename, index)) DbfError: D:\Data_RP\data\projects\kN\GIS\shapes\SWM_4N.dbf is closed; record 0 is unavailable </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload