Python gspread update_cell 在一个函数中接受参数,在另一个函数中接受错误

Python gspread update_cell accepts arguments in one function, error in another

目前正在使用 python 和 gspread 作为练习我 运行 遇到了一个神秘的错误。

我有获取小区更新信息的功能:

def update():
    row = get_row()
    col = get_column()
    if (update_validation(row, col)):
        content = get_update_content(col)
        pp.pprint(content)
        really_update(row, col, content)
    else:
        moreinput()

和一个额外的功能来更新单元格以供以后重用:

def really_update(row, col, content):
    sheet.update_cell(row, col, content)

这两个函数相互配合没问题。 但是,使用此功能添加列:

def add_column():
    row = str(0)
    col = str(len(columns)+1)
    print(row)
    print(col)
    add_format()
    name = make_col_name()
    print(name)
    print(type(row), ', ', type(col), ', ',type(name))
    #print(sheet.cell(row,col).value())
    #sheet.update_cell(row, col, name)

如您所见,我尝试进行一些调试以查看类型是否匹配。 他们这样做了,但仍然抛出以下错误:

File "test.py", line 184, in main
    add_column()
File "test.py", line 156, in add_column
    print(sheet.cell(row,col).value())
File "C:\Python37\lib\site-packages\gspread\models.py", line 514, in cell
    range_label = '%s!%s' % (self.title, rowcol_to_a1(row, col))
File "C:\Python37\lib\site-packages\gspread\utils.py", line 118, in 
    rowcol_to_a1
raise IncorrectCellLabel('(%s, %s)' % (row, col))
    gspread.exceptions.IncorrectCellLabel: (0, 8)

我所做的任何调试都没有帮助解决这个问题, 该文档也没有帮助。

知道哪里出了问题吗? (希望它不是像丢失的':'那样我会感觉很糟糕) 提前致谢。

看起来 row 在你的情况下是 0:

raise IncorrectCellLabel('(%s, %s)' % (row, col))
    gspread.exceptions.IncorrectCellLabel: (0, 8)

gspread.utils.rowcol_to_a1() 引发异常,接受从 1 开始的行和列值。文档对此有明确说明:

Parameters:

  • row (int, str) – The row of the cell to be converted. Rows start at index 1.
  • col – The column of the cell to be converted. Columns start at index 1.