0

I am receiving an Invalid Syntax error on my except statement. The code runs fine until I add in the except

import pyautogui
print('Press Ctrl-C to quit.')
while True:
     pyautogui.click(1624, 967)
except KeyboardInterrupt:
    print('\nDone.')

I'm sure I'm just missing something silly.

Thank you!

3
  • Well... it's because that's invalid syntax. Consider putting that pyautogui.click call in a try block... that's where the except should go. Don't forget to break. Commented Jun 27, 2017 at 15:41
  • 2
    Except without a try is like else without an if. Commented Jun 27, 2017 at 15:42
  • 2
    @AlanLeuthard More like elif; else works with while and for as well :) Commented Jun 27, 2017 at 15:43

1 Answer 1

1

You forgot to add try statement.

import pyautogui
print('Press Ctrl-C to quit.')

try:
    while True:
        pyautogui.click(1624, 967)
except KeyboardInterrupt:
    print('\nDone.')
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.