问题
Can someone say why python doesn't allow this?
# -*- coding: utf-8 -*
import win32api,win32con,os,time,sys
x_pad =464
y_pad =235
def tik():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
time.sleep(.1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
print "Click.".decode('utf-8').encode(sys.stdout.encoding) #completely optional. But nice for debugging purposes.
def basilitut():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
time.sleep(.1)
print 'Hold'.decode('utf-8').encode(sys.stdout.encoding)
def birak():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
time.sleep(.1)
print 'Release.'.decode('utf-8').encode(sys.stdout.encoding)
def mousePos(cord):
win32api.SetCursorPos((x_pad + cord[0], y_pad + cord[1])
def oyun():
#Ses kes
mousePos((163, 251))
tik()
time.sleep(.1)
#Play butonu
mousePos((161, 127))
tik()
time.sleep(.1)
#Iphone
mousePos((149, 267))
tik()
time.sleep(.1)
#Merhaba
mousePos((373, 314))
tik()
time.sleep(.1)
#Goal
mousePos((163, 251))
tik()
time.sleep(.1)
File "C:\Users\Doruk\Desktop\Python\Bot\code.py", line 27
def oyun():
^
SyntaxError: invalid syntax
And when I remove that def oyun(): blablabla
File "C:\Users\Doruk\Desktop\Python\Bot\code.py", line 24
^ SyntaxError: invalid syntax
It just gives the error with blank line.
And when I delete
def mousePos(cord):
win32api.SetCursorPos((x_pad + cord[0], y_pad + cord[1])
It works but I can't make my program without them.
回答1:
Look at the code immediately above the reported error:
def mousePos(cord):
win32api.SetCursorPos((x_pad + cord[0], y_pad + cord[1])
You're missing a closing parentheses.
回答2:
You sure there's no syntax error?
win32api.SetCursorPos((x_pad + cord[0], y_pad + cord[1])
12 2 1???
The line that a syntax error is reported on is not necessary where the syntax error is. It's merely the first place where an earlier syntax error caused the parser to realize that something's wrong.
来源:https://stackoverflow.com/questions/38384778/python-gives-syntax-error-but-there-is-no-mistake