问题
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