You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

向Google Sheets写入变量值失败求助:update_cell方法问题

问题解决方法

首先明确update_cell方法的正确调用格式:需要传入行号、列号、要写入的值三个参数,你之前的错误出在参数传递上:

错误原因分析

  • 第一种写法userscore.update_cell(3,1, + username)里的+ username是多余的语法错误,不需要在变量前加加号,直接传入变量即可。
  • 第二种写法userscore.update_cell(username)只传了一个参数,不符合方法要求的参数数量,必然报错。

正确代码示例

username = input("Please enter username: ")
# 按你之前的固定单元格位置写入,直接传变量即可
userscore.update_cell(3, 1, username)

如果不关心具体单元格位置,也可以用更灵活的方式追加到表格末尾:

username = input("Please enter username: ")
# 追加一行数据到表格
userscore.append_row([username])

内容的提问来源于stack exchange,提问作者Philip Doyle

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 02:09:50