我有一个应更改的变量,名为“ scrolldown”。它不会从0更改,但我不知道为什么。这是我的代码。任何帮助表示赞赏。出于某种原因,无论何时python打印变量“ scrolldown”,它始终为0,无论它应该经过0 + 1多少次。我都尝试将变量从int(scrolldown)更改为向下滚动并从+1到+ 1但都不行。该变量在开始时定义为“ 0”,但我不明白为什么这会引起问题。为什么在脚本运行时不更改此变量?
scrolldownunits = int(903 - 553)
scrolldown = 0
Test2 = True
def movelisting():
print(scrolldown)
for i in range(scrolldown):
scrolldowncalc = scrolldown * int(scrolldownunits) * -1
pyautogui.scroll(scrolldowncalc)
pyautogui.click()
time.sleep(5)
movelisting1 = 1
Test2 = False
listingcheck()
def listingcheck():
if Test2 == True:
movelisting1 = 0
scrolldown = 0
if movelisting1 != 1:
pyautogui.moveTo(914, 499) ##CLICK ON EBAY LISTING
pyautogui.click()
time.sleep(5)
if pyautogui.locateOnScreen('NoClothing.png') != None: ###something not working here
i = True
o = pyautogui.locateOnScreen('BackArrow.png')
print(o)
p = pyautogui.center(o)
pyautogui.click(p)
time.sleep(5)
pyautogui.moveTo(914, 499)
time.sleep(2)
scrolldown = scrolldown +1
movelisting()
elif pyautogui.locateOnScreen('NoBikes.png') != None: ###SEARCHES FOR THINGS WE DONT WANT
h = True
c = pyautogui.locateOnScreen('BackArrow.png')
d = pyautogui.center(c)
pyautogui.click(d)
time.sleep(5)
pyautogui.moveTo(914, 499)
time.sleep(2)
scrolldown = scrolldown +1
movelisting()
elif pyautogui.locateOnScreen('NoSelections.png') != None:
g = True
e = pyautogui.locateOnScreen('BackArrow.png')
f = pyautogui.center(e)
pyautogui.click(f)
time.sleep(5)
pyautogui.moveTo(914, 499)
time.sleep(2)
scrolldown = scrolldown +1
movelisting()
listingcheck1 = True ##USED FOR VAR DELETE
listingcapture() ###CONTINUES ONTO NEXT STEP
答案 0 :(得分:0)
在函数内部分配全局变量时,首先需要让Python知道您打算修改全局变量。默认情况下,当您进行分配时,Python将在函数范围内创建一个具有相同名称的新变量。将“全局向下滚动”添加到listingcheck()的顶部。