如何在python中划分游标的结果



如何划分游标的结果。例子:我从游标结果中获得了1,000,000个数据。那么我将把它分成3部分。

a = part 1
b = part 2
c = part 3

和每个section将在线程中循环。我希望你能帮助我。

mycode

#my thread
def myThread(data):
#loop
for row in data:
getAPIResponse(row)

#get from db
sql = "SELECT * FROM myTable"
cursor.execute(sql)
result = cursor.fetchall()
#divide to 3 parts
part1=???
part2=???
part3=???
#run thread
try:
_thread.start_new_thread( myThread, (part1) )
_thread.start_new_thread( myThread, (part2) )
_thread.start_new_thread( myThread, (part3) )
except:
print ("Error: unable to start thread")

请记住,在" cursor.fetchall() " &quot之后,您所拥有的只是一个普通列表。

third = len(result)//3
part1 = result[0:third]
part2 = result[third:third*2]
part3 = result[third*2:]

最新更新