# Issue with Read/Write DBF datafile using dbf module

**URL:** <https://forum.inductiveautomation.com/t/issue-with-read-write-dbf-datafile-using-dbf-module/79722>\
**Category:** Ignition\
**Created:** [September 27, 2023, 3:32pm UTC](https://forum.inductiveautomation.com/t/issue-with-read-write-dbf-datafile-using-dbf-module/79722 "2023-09-27T15:32:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chaoliang](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@chaoliang](https://forum.inductiveautomation.com/u/chaoliang)\
**Post date:** [September 27, 2023, 3:32pm UTC](https://forum.inductiveautomation.com/t/issue-with-read-write-dbf-datafile-using-dbf-module/79722/1 "2023-09-27T15:32:37Z")

</div>

I am trying to use dbf module for read and write of the DBF database file.

> **[dbf](https://pypi.org/project/dbf/)**
>
> Pure python package for reading/writing dBase, FoxPro, and Visual FoxPro .dbf files (including memos)

I got the needed functions prepared and tested in VSCode, but when testing them in Ignition Script console, I can read but cannot write value to the db.

The following script has been tested in VSCode.  
When testing it in Ignition, the table can be created but no values are added to the table.  
before running the script.

1. copy dbf and aenum module to ignition module folder.  
C:\Program Files\Inductive Automation\Ignition\user-lib\pylib

```auto
## code to work with dbf module aenum-2.1.2 dbf-0.97.11

import dbf

table = dbf.Table('C:\\Users\\xxxx\\Documents\\DBF\\newRecipe.DBF', 'name C(30); age N(3,0); birth D')

print('db definition created with field names:', table.field_names)

table.open(mode=dbf.READ_WRITE)
for datum in (('John Doe', 31, dbf.Date(1979, 9,13)),
              ('Ethan Furman', 102, dbf.Date(1909, 4, 1)),
              ('Jane Smith', 57, dbf.Date(1954, 7, 2)),
              ('John Adams', 44, dbf.Date(1967, 1, 9)),):
    table.append(datum)

print ('records added:')
for record in table:
    print (record)
    print ('-----')

table.close()

table.open(mode=dbf.READ_WRITE)

table.add_fields('telephone C(10)')

telephones = {'John Doe': '1234', 
              'Ethan Furman': '2345', 
              'Jane Smith': '3456', 
              'John Adams': '4567'}
for record in table:
    with record as r:
        r.telephone = telephones[r.name.strip()]

print ('updated records')
for record in table:
    print (record)
    print ('-----')

```

Maybe issue is at the following new data list, but I cannot figure out why it behaves different in ignition.

```auto
for datum in (('John Doe', 31, dbf.Date(1979, 9,13)),
              ('Ethan Furman', 102, dbf.Date(1909, 4, 1)),
              ('Jane Smith', 57, dbf.Date(1954, 7, 2)),
              ('John Adams', 44, dbf.Date(1967, 1, 9)),):

```

Appreciate if anyone can help with troubleshooting.

---

<div class="post-metadata">

**Author:** ![chaoliang](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@chaoliang](https://forum.inductiveautomation.com/u/chaoliang)\
**Post date:** [September 28, 2023, 12:12am UTC](https://forum.inductiveautomation.com/t/issue-with-read-write-dbf-datafile-using-dbf-module/79722/2 "2023-09-28T00:12:29Z")

</div>

> [@chaoliang](#):
>
> ```auto
> table = dbf.Table('C:\\Users\\xxxx\\Documents\\DBF\\newRecipe.DBF', 'name C(30); age N(3,0); birth D')
> 
> print('db definition created with field names:', table.field_names)
> 
> table.open(mode=dbf.READ_WRITE)
> for datum in (('John Doe', 31, dbf.Date(1979, 9,13)),
> ('Ethan Furman', 102, dbf.Date(1909, 4, 1)),
> ('Jane Smith', 57, dbf.Date(1954, 7, 2)),
> ('John Adams', 44, dbf.Date(1967, 1, 9)),):
> table.append(datum)
> 
> ```

The script can create a dbf file.  
It can also add the headers.  
But the data cannot be inserted.

```auto
 table.append(datum)

```

The above script is not doing the work.

Also when testing in script console, I found the color difference.  
The table.open is light yellow color but the table.append is black color.  
What is the difference?  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/4/94bcdcf9ffbb8110dcbe55848f330ca7b1ab7a46.png)

---

<div class="post-metadata">

**Author:** ![chaoliang](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@chaoliang](https://forum.inductiveautomation.com/u/chaoliang)\
**Post date:** [October 1, 2023, 7:31am UTC](https://forum.inductiveautomation.com/t/issue-with-read-write-dbf-datafile-using-dbf-module/79722/3 "2023-10-01T07:31:26Z")

</div>

Spent 2 days troubleshooting the issue and went down to the module details.

I found the table write function is not working under ignition, but working using python 3.x.

Not sure whether it's the issue with Jython2.7.

Anyway, instead of troubleshooting it further, I went alternative way, to call the external python 3 to run the script instead.

Issue resolved.

Here's the link for calling python3 from ignition.

> **[Python In Ignition](https://support.inductiveautomation.com/hc/en-us/articles/360056397252-Python-In-Ignition)**
>
> An Advanced Primer — Python, Libraries, Versions, and the Future
>  
> Background
> Ignition provides users with the ability to do Python scripting as a core part of the Ignition platform. Standard Editi...
