# Hi Guys, 
I'm running a python script which is attached to a grid iterator. Each time the python script runs the table name changes. I want to append this data to a grid variable. The data is not being saved

**URL:** <https://matillioncommunity.discourse.group/t/hi-guys-im-running-a-python-script-which-is-attached-to-a-grid-iterator-each-time-the-python-script-runs-the-table-name-changes-i-want-to-append-this-data-to-a-grid-variable-the-data-is-not-being-saved/1590>\
**Category:** Matillion ETL\
**Created:** [December 9, 2021, 2:27pm UTC](https://matillioncommunity.discourse.group/t/hi-guys-im-running-a-python-script-which-is-attached-to-a-grid-iterator-each-time-the-python-script-runs-the-table-name-changes-i-want-to-append-this-data-to-a-grid-variable-the-data-is-not-being-saved/1590 "2021-12-09T14:27:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Suhayr](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@Suhayr](https://matillioncommunity.discourse.group/u/Suhayr)\
**Post date:** [December 9, 2021, 2:27pm UTC](https://matillioncommunity.discourse.group/t/hi-guys-im-running-a-python-script-which-is-attached-to-a-grid-iterator-each-time-the-python-script-runs-the-table-name-changes-i-want-to-append-this-data-to-a-grid-variable-the-data-is-not-being-saved/1590/1 "2021-12-09T14:27:51Z")

</div>

How do I append to a grid variable without it being wiped out every time the python scrip runs.

---

<div class="post-metadata">

**Author:** ![Bryan](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@Bryan](https://matillioncommunity.discourse.group/u/Bryan)\
**Post date:** [December 9, 2021, 6:49pm UTC](https://matillioncommunity.discourse.group/t/hi-guys-im-running-a-python-script-which-is-attached-to-a-grid-iterator-each-time-the-python-script-runs-the-table-name-changes-i-want-to-append-this-data-to-a-grid-variable-the-data-is-not-being-saved/1590/2 "2021-12-09T18:49:35Z")

</div>

Hi [@Suhayr](https://matillioncommunity.discourse.group/u/Suhayr)​, after catching a glimpse of an earlier post, I wanted to give you some advice that I learned along the way. Only use Jython as an absolute last resort. Jython is based on Python 2 which means only Python 2 functionality is available to you while using it. The fact that Jython hasn't been updated to Python 3 yet should make you nervous about it's future.

With that said here is an example of how to append to a grid variable using Python when it's attached to an iterator:

# Get the current grid variable values and store them in a local variable

gv = context.getGridVariable('Your\_Grid\_Var\_Name')

# If the Grid Variable is empty (None) then we will intantiate gv with an empty list that we will add to

if gv == None:

gv = []

# Assuming your gridvariable has 4 columns and they are in the following order:

# database, schema, table, table\_row\_count

# Create a list of values that match the order defined in your grid variable

new\_grid\_var\_row = ['my\_database', 'my\_schema', 'my\_table', '5']

# Append the row of values we just created to our local variable

gv.append(new\_grid\_var\_row)

# If rows were appended then update the Matillion GridVariable using our local variable

if gv != []:

context.updateGridVariable('Your\_Grid\_Var\_Name', gv)

I hope this helps!
