步骤1:读取文件
#read the csv file
with open('myfile.csv', 'rt') as csvfile:
reader = csv.reader(csvfile, dialect='excel')
reader_list = list(reader)
for row in reader_list:
print(row[0])
print(type(row[0])) #printing the type just for illustration
输出
'171667494.1541516384'
<class 'str'>
'548162985.1541558366'
<class 'str'>
'149398364.1541533183'
<class 'str'>
'888359874.1541543604'
<class 'str'>
'1628297960.1541566771'
步骤2:我想将完全相同的字符串(带单引号)传递给google API,如下所示。我该如何摆脱呢?
for row in reader_list:
user_deletion_request_resource.upsert(
body = {
"id": { # User ID.
"userId": row[0], # I am passing the strings here
"type": "CLIENT_ID"
}}
).execute()
由于某些原因,API会使用额外的引号,如下所示的userId
{'id': {'type': 'CLIENT_ID', 'userId': "'785972698.1540375322'"}, 'deletionRequestTime': '2020-02-03T08:25:16.796Z'}
尝试
"userId": row[0].replace("'", "")
那应该用空格去除刻度线。