dbfpy

880
6
09-19-2019 12:42 PM
JoeBorgione
MVP Esteemed Contributor

I need to revive a deprecated python script that originally was written with 2.x python and an older (than 10.6) version of ArcGIS Desktop.

It imports dbfpy and from dfbpy imports dbf.  I'm not familiar with it, except for the obvious that it allows dbf files to be read and written to.

My googling so far hasn't found a 3.x equivalent.  Is there one?  I notice in the ArcGIS Pro 2.4  Add packages pane, there is dbf:

I'm not sure if I'll end up porting this script to 3.x or not, but I want to hedge my bets if I do....

That should just about do it....
Tags (2)
0 Kudos
6 Replies
JoshuaBixby
MVP Esteemed Contributor

Is the script already using ArcPy?  If so, just use ArcPy functions or ArcGIS geoprocessing tools.

JoeBorgione
MVP Esteemed Contributor

As I dig into this thing, it seems quite antiquated.  I think it's going to require a complete over haul, but figuring out the logic is going to be quite the challenge. From an Idle/Python 2.7.14 shell I get:

Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import dbfpy

Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import dbfpy
ImportError: No module named dbfpy
>>> from dbfpy import dbf

Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from dbfpy import dbf
ImportError: No module named dbfpy
>>>

To answer your question Johsua, yes, it uses arcpy functions/gp tools.  It uses one I haven't seen... ever...: arcpy.SetProduct("ArcInfo")

That should just about do it....
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

If the scripts are already using arcpy, I would just use various arcpy functions or geoprocessing tools to interact with DBFs.  The less modules you need to import and rely on, the better.

MichaelVolz
Esteemed Contributor

You should be able to comment out the set product statement as that has not been required for some time.  Good luck!!

JoeBorgione
MVP Esteemed Contributor

Yeah... that's the least of it....  

That should just about do it....
0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

conda options for dbf ... try to avoid pip Joe

https://anaconda.org/anaconda/dbf    # also listed here for python 3.6/3.7, but not installed by default

Packages for 64-bit Windows with Python 3.7 — Anaconda 2.0 documentation 

Also comes up but not distributed in the package

https://anaconda.org/conda-forge/dbfread