Results of a query to a grid variable in Python/Jython are not straightforward and the documentation or examples just don't seem to exist. I had to use this method for my project instead of query results to grid like I normally do.
This is an example and it's the absolute minimum required to get a grid variable populated from a simple query using Python/Jython.
I was getting a cast exception PyTuple to PyList with my query results when attempting to update the grid variable I had setup to hold the contents of the query. The following works (Jython) and I don't get any cast problems when running the script. I'm sure there's a much better way of doing this but I've only been using Python/Jython for about a year whereas I've been using C# for over 10.
My grid variable (jv_grid_variable_example) has four columns and potentially many rows.
sql = "SELECT Col1, Col2, Col3, Col4 FROM DBName.Information_Schema.Tables WHERE TABLE_TYPE LIKE '%TABLE%'"
myCursor = context.cursor()
myCursor.execute(sql)
myResultSet = cursor.fetchall()
#results look like: ([u'Value1', u'Value2', u'Value3', u'Value4'], [u'Value1', u'Value2', u'Value3', u'Value4'], ...)
#put the results from the query into the proper type the grid variable expects (list)
myVariablePayload = [List(i) for i in myResultSet]
#results look like: [[u'Value1', u'Value2', u'Value3', u'Value4'], [u'Value1', u'Value2', u'Value3', u'Value4'], ...]
content.updateGridVariable('jv_grid_variable_example', myVariablePayload)
The example adds one more step to the normal process of populating variables with Python/Jython in the script task by turning the results into a list instead of a tuple. You can try on your own and use the print statements on the two variables with results to see the difference in the output.
Hopefully this saves some folks from searching instead of creating.