我的代码:
with connection:
with connection.cursor() as cursor:
sql = """
SELECT `CPC-Current-DWPI`,`Assignee/Applicant First` FROM final.f01l_patent;
"""
cursor.execute(sql)
result = cursor.fetchall()
count = []
ro=0
for i in range(1,10):
for j in result :
if j['CPC - Current - DWPI.split()'][3]==str(i):
co+=1
count.append(co)
co=0
我知道我不能用列表索引元组,所以我在CPC - Current - DWPI之后添加了。split(),但实际上我不知道如何将列表更改为切片
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~AppDataLocalTempipykernel_193121811172777.py in <module>
16 for i in range(1,10):
17 for j in result :
---> 18 if j['CPC - Current - DWPI.split()'][3]==str(i):
19 co+=1
20 count.append(co)
TypeError: tuple indices must be integers or slices, not str
您的result
是Tuple
的列表。尝试用您想要的项目的索引(作为整数)替换字符串'CPC - Current - DWPI.split()'
。