Question:
What is wrong with this?
Repl link:
planning on keeping this private
code snippet
![eof while parsing|690x284](upload://ug1HhiV8hKOvfORZfv3qyIJKti1.png)
code you can use:
pyautogui.position(x,y)
pyautogui.click(x,y)
file = open("script.txt", "r")
try:
for line in file:
for char in line:
pyautogui.typewrite(char)
So the interpreter reaches the end of the file before it sees the completion of the try-except block. To fix, write an except or finally statement for that try block.
edit: added finally
1 Like
can you give me an example where to put the except block?
pyautogui.position(x,y)
pyautogui.click(x,y)
file = open("script.txt", "r")
try:
for line in file:
for char in line:
pyautogui.typewrite(char)
except:
print("An exception was caught!")
finally:
print("Just showing for completeness.")
print("you can have either except or finally to fix your specific problem.")
print("The finally statement will always run, regardless if exceptions were caught.")
2 Likes