insert_row or append_row with Gspread python

独自空忆成欢 提交于 2020-04-30 07:40:27

问题


When I run my script insert_row and append_row are putting each letter of the string into a new column.

Trying to insert an id '877' for example.

Didn't like integers

worksheet.append_row(877)

Returns

*** TypeError: object of type 'int' has no len()

Tried wrapping this in the str() and it creates a new column for each letter.

What am I doing wrong?!


回答1:


Strings have lenght (number of characters); integers don't. If you want to achieve a similar result, do this:

worksheet.append_row('877')

But in case you want the id in only one column, pass it as a list of one element:

worksheet.append_row([877])

EDIT:

worksheet.append_row gets an iterable element, and saves it in as many rows as it needs to iterate through it. e.g. [1,2,3,'asd'] will write four columns, one with each value. When you pass as a string, since strings are iterable, it saves each character in a separate column.



来源:https://stackoverflow.com/questions/31248734/insert-row-or-append-row-with-gspread-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!