Answer the question
In order to leave comments, you need to log in
Problems involving gspread in python
Good day
A copy of my post from python.su :)
Introduction:
There is a Google Spreadsheet (hereinafter just a table), columns Number, Balance, and a number of cells
There is a script. It implements a number parameter class, incl. attributes row (number of the row in which the number is located in the table) and cells (list of table cells located on the same line as the number)
There is a base dictionary in which the key is the phone number, and the value is an instance of the number parameters class.
I am using the gspread module.
wks_range - list of all table cells. One element of the list is an instance of the gspread.cell class with row, cell and value attributes. If you display one of the elements of the list, it will look like this:
Obviously, R is the number of the row where the cell is located, C is the number of the column, row is the value of the cell
Part of the script:
for num in base.keys():
for cell in wks_range:
if base[num].row==cell.row:
base[num].cells.append(cell)#ячейки, относящиеся к номеру
>>> for num in base.keys():
base[num].cells=[]
>>> for num in base.keys():
for cell in wks_range:
if base[num].row==cell.row and base[num].row!=None:
base[num].cells.append(cell)
if len(base[num].cells)>4:
print(num)
for num in list(base.keys())[:30]:
for cell in wks_range:
if base[num].row==cell.row:
base[num].cells.append(cell)
>>> base['9030064337'].cells
[<Cell R220C1 '9037551123'>, <Cell R220C2 '-1782.88'>, <Cell R220C3 None>, <Cell R220C4 None>, <Cell R51C1 '9030064337'>, <Cell R51C2 '-5003.47'>, <Cell R51C3 None>, <Cell R51C4 None>, <Cell R130C1 '9055669265'>...
...
if base[num].row==cell.row:
print('{} {} {}'.format(num,base[num].row,cell))
9030064337 51 <Cell R51C1 '9030064337'>
9030064337 51 <Cell R51C2 '-5003.47'>
9030064337 51 <Cell R51C3 None>
9030064337 51 <Cell R51C4 None>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question