Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python,传递一个变量,使其';它被认为是一种属性_Python_Variables_Object_Attributes - Fatal编程技术网

python,传递一个变量,使其';它被认为是一种属性

python,传递一个变量,使其';它被认为是一种属性,python,variables,object,attributes,Python,Variables,Object,Attributes,如何传递变量,使其被识别为属性?我得到的确切错误是 AttributeError:“电子表格”对象没有属性“行” 我正在做的是使用gspread库将数据写入谷歌表单 这个代码有效 wks = gc.open(row['sheet']).sheet1 但是这个代码不起作用 wks = gc.open(row['sheet']).row['worksheet'] 不同的是,如果我硬编码希望写入的工作表值sheet1,则没有错误,但如果我将sheet1作为值传递到变量行['sheet'],则会得到

如何传递变量,使其被识别为属性?我得到的确切错误是

AttributeError:“电子表格”对象没有属性“行”

我正在做的是使用gspread库将数据写入谷歌表单

这个代码有效

wks = gc.open(row['sheet']).sheet1
但是这个代码不起作用

wks = gc.open(row['sheet']).row['worksheet']

不同的是,如果我硬编码希望写入的工作表值sheet1,则没有错误,但如果我将sheet1作为值传递到变量行['sheet'],则会得到错误

让我将代码作为

temp = gc.open(row['sheet'])
wks = temp.row['worksheet']
我认为temp中没有名为row的变量,这就是为什么会出现属性错误。只是为了检查行是否作为temp的属性存在,请使用dir(temp)或vars(temp)


希望能对你有所帮助。

这实际上是正确的方法