如何解决Python:^ SyntaxError:解析时出现意外的EOF
您好,我的代码中有错误,但我不明白问题所在。你可以帮助我 ? 这是错误:^ SyntaxError:解析时出现意外的EOF
# Combat
nike = None
tour = "tour.png"
win = "win.png"
sort = "sort.png"
end = pyautogui.locateOnScreen(win)
while nike == None:
try:
nike = pyautogui.locateOnScreen(tour)
pyautogui.press("b")
attack = pyautogui.locateOnScreen("attack.png",confidence=0.7)
pyautogui.moveto(attack)
pyautogui.click()
pyautogui.press("b")
attack = pyautogui.locateOnScreen("attack.png",confidence=0.7)
pyautogui.moveto(attack)
pyautogui.click()
pyautogui.press("f1")
end = pyautogui.locateOnScreen(win)
if end != None:
pyautogui.press("enter")
break
解决方法
你的代码缩进不符合标准,catch块也是强制性的,try块修复这些东西使你的代码像下面一样
# Combat
nike = None
tour = "tour.png"
win = "win.png"
sort = "sort.png"
end = pyautogui.locateOnScreen(win)
while nike == None:
try:
nike = pyautogui.locateOnScreen(tour)
pyautogui.press("b")
attack = pyautogui.locateOnScreen("attack.png",confidence=0.7)
pyautogui.moveTo(attack)
pyautogui.click()
pyautogui.press("b")
attack = pyautogui.locateOnScreen("attack.png",confidence=0.7)
pyautogui.moveTo(attack)
pyautogui.click()
pyautogui.press("f1")
end = pyautogui.locateOnScreen(win)
if end != None:
pyautogui.press("enter")
break
except Exception as e:
print(e)
运行良好,没有任何 EOF 文件解析错误
,您可以尝试添加:
except:
break
与 try
缩进相同
喜欢:
# Combat
nike = None
tour = "tour.png"
win = "win.png"
sort = "sort.png"
end = pyautogui.locateOnScreen(win)
while nike == None:
try:
nike = pyautogui.locateOnScreen(tour)
pyautogui.press("b")
attack = pyautogui.locateOnScreen("attack.png",confidence=0.7)
pyautogui.moveTo(attack)
pyautogui.click()
pyautogui.press("b")
attack = pyautogui.locateOnScreen("attack.png",confidence=0.7)
pyautogui.moveTo(attack)
pyautogui.click()
pyautogui.press("f1")
end = pyautogui.locateOnScreen(win)
if end != None:
pyautogui.press("enter")
break
except:
break
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。