无法让 pygsheets 接受读取 CSV 的列表格式
import pygsheets
import csv
gc = pygsheets.authorize(service_file=service_account_file)
# Open spreadsheet
sh = gc.open_by_key(spreadsheet_key)
# Open Worksheet
wks = sh.worksheet_by_title(spreadsheet_hosts_worksheet)
with open('sheets-data/Sheets-Hosts-Export.csv', 'r') as f:
reader = csv.reader(f, skipinitialspace=True, delimiter=',', quotechar='"')
data = list(reader)
wks.update_values(cell_list=data)
但是我得到的输出是:
Traceback (most recent call last):
File "./push-sheets-hosts-data.py", line 47, in <module>
wks.update_values(cell_list=data)
File "/usr/local/lib/python3.5/dist-packages/pygsheets/worksheet.py", line 573, in update_values
tmp_row.append(cell_list[row][col].value)
TypeError: list indices must be integers or slices, not list
但是消息来源显示它正在检查列表?请问我哪里错了?资源
第一个和第二个字段仅供参考:来自
print(data[0])
print(data[1])
['host_name', 'alias', 'address', 'parents', 'use', 'display_name', 'hostgroups', 'contacts', '_ADDINFO', '_SNOWGROUP', '_RTTCRIT', '_RTTWARN', 'contact_groups', 'notes', 'notes_url', 'check_command', 'first_notification_delay', 'check_interval', 'max_check_attempts', 'retry_interval', 'config_filename']
['host', 'destiny islands', '1.1.1.1', 'host.mypalace.com,host.mapalace2.com', 'tmpl_network_device', 'Gingerbread lane', 'hgrp_grandad', '', 'ACTION - Don't forget to smile', 'test', '70', '20', '', '', '', '', '', '', '', '', '/folder/filename']