In C language I was used to doing this by passing address of variables (pass by reference), but in Python, despite having already read about some alternatives, I have no ideia how can I do to pass a Google Sheet (worksheet) to a function that must change and save it online, using gspread library.
Here is my code:
def ordenar(self, list):
sheet = len(list.worksheets())
for i in range(sheet):
lista = list.get_worksheet(i).row_values(1)
lista.sort()
size = len(lista)
if size > 1:
cell_list = list.get_worksheet(i).range(1, size)
j = 0
for cell in cell_list:
cell.value = lista[j]
j = j+1
# Update in batch
list.get_worksheet(i).update_cells(cell_list)
Now the part of the main code that uses the function:
#Teste de ordenação
Jose.vocabulario.ordenar(Jose.vocabulario.artigo)