【发布时间】:2021-03-23 05:52:04
【问题描述】:
我是 python 循环的新手,如果 google 表格上特定单元格的值更改为 30 或以下,我会尝试结束循环。我尝试使用“继续”而不是“中断”,并且尝试缩进下一个循环以与 if 语句对齐,但似乎没有任何效果。第一个循环运行良好,但是当满足正确的条件时,它不会继续到下一个循环,只是重复第一个循环。到目前为止,这是我所拥有的:
for b in range(179):
time.sleep(5)
#Get screenshot
pyautogui.screenshot("Volume.png")
#Crop out volume number
im = Image.open("Volume.png")
x1 = 2570
y1 = 607
x2 = 2671
y2 = 637
cropped = im.crop((x1, y1, x2, y2))
cropped.save("Volume.png")
#Convert image to text
img = cv2.imread("Volume.png")
text = image_to_string(img)
#Import current volume
sheet.update_cell(3,2, text)
change = sheet.cell(3,5).value
floatt = float(change)
if floatt <= 30:
break
#Start price
for c in range(1):
#Get screenshot
pyautogui.screenshot("Price.png")
#Crop out price number
im = Image.open("Price.png")
x1 = 1854
y1 = 988
x2 = 2074
y2 = 1036
cropped = im.crop((x1, y1, x2, y2))
cropped.save("Price.png")
#Convert image to text
img = cv2.imread("Price.png")
text = image_to_string(img)
#Import start price
sheet.update_cell(9,2, text)
【问题讨论】:
标签: loops if-statement google-sheets break continue