本文介绍了Python给出语法错误但没有错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人能说为什么python不允许这样做吗?
# -*- 编码:utf-8 -*导入 win32api,win32con,os,time,sysx_pad =464y_pad =235def tik():win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)时间.睡眠(.1)win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)print "Click.".decode('utf-8').encode(sys.stdout.encoding) #完全可选.但用于调试目的很好.def basilitut():win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)时间.睡眠(.1)打印 'Hold'.decode('utf-8').encode(sys.stdout.encoding)def birak():win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)时间.睡眠(.1)打印 'Release.'.decode('utf-8').encode(sys.stdout.encoding)def mousePos(cord):win32api.SetCursorPos((x_pad + cord[0], y_pad + cord[1])def oyun():#Ses kesmousePos((163, 251))抖音()时间.睡眠(.1)#播放按钮mousePos((161, 127))抖音()时间.睡眠(.1)#苹果手机mousePos((149, 267))抖音()时间.睡眠(.1)#梅哈巴mousePos((373, 314))抖音()时间.睡眠(.1)#目标mousePos((163, 251))抖音()时间.睡眠(.1)
文件C:\Users\Doruk\Desktop\Python\Bot\code.py",第 27 行
定义 oyun():
^
语法错误:无效语法
当我删除那个 def oyun(): blablabla
文件C:\Users\Doruk\Desktop\Python\Bot\code.py",第 24 行
^ SyntaxError: 无效语法
它只是给出了带有空行的错误.
当我删除
def mousePos(cord):win32api.SetCursorPos((x_pad + cord[0], y_pad + cord[1])
它可以工作,但没有它们我无法制作我的程序.
解决方案
直接看上面报错的代码:
def mousePos(cord):win32api.SetCursorPos((x_pad + cord[0], y_pad + cord[1])
您缺少一个右括号.
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)
And when I remove that def oyun(): blablabla
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.
解决方案
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.
这篇关于Python给出语法错误但没有错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!