为什么第41行的“def”会在这里出现语法错误?

时间:2017-10-09 01:38:22

标签: python syntax

我的代码如下:

import keyboard, clipboard, time
from appscript import app, k
def copyChecker():
    if (keyboard.is_pressed('control+w+1')):
        app('System Events').keystroke('V', using=k.command_down)
        copy1 = clipboard.paste()[: -len(clipboard.paste())]
        #print(copy1)

    if (keyboard.is_pressed('control+w+2')):
        app('System Events').keystroke('V', using=k.command_down)
        copy2 = clipboard.paste()[: -len(clipboard.paste())]

    if (keyboard.is_pressed('control+w+3')):
        app('System Events').keystroke('V', using=k.command_down)
        copy3 = clipboard.paste()[: -len(clipboard.paste())]

    if (keyboard.is_pressed('control+w+4')):
        app('System Events').keystroke('V', using=k.command_down)
        copy4 = clipboard.paste()[: -len(clipboard.paste())]

    if (keyboard.is_pressed('control+w+5')):
        app('System Events').keystroke('V', using=k.command_down)
        copy5 = clipboard.paste()[: -len(clipboard.paste())]

    if (keyboard.is_pressed('control+w+6')):
        app('System Events').keystroke('V', using=k.command_down)
        copy6 = clipboard.paste()[: -len(clipboard.paste())]

    if (keyboard.is_pressed('control+w+7')):
        app('System Events').keystroke('V', using=k.command_down)
        copy7 = clipboard.paste()[: -len(clipboard.paste())]

    if (keyboard.is_pressed('control+w+8')):
        app('System Events').keystroke('V', using=k.command_down)
        copy8 = clipboard.paste()[: -len(clipboard.paste())]

    if (keyboard.is_pressed('control+w+9')):
        app('System Events').keystroke('V', using=k.command_down)
        copy9 = clipboard.paste()[: -len(clipboard.paste())

def pasteChecker():
    if (keyboard.is_pressed('control+s+1')):
        clipboard.copy(copy1)
        app('System Events').keystroke('V', using=k.command_down)

    if (keyboard.is_pressed('control+s+2')):
        clipboard.copy(copy2)
        app('System Events').keystroke('V', using=k.command_down)

    if (keyboard.is_pressed('control+s+3')):
        clipboard.copy(copy3)
        app('System Events').keystroke('V', using=k.command_down)

    if (keyboard.is_pressed('control+s+4')):
        clipboard.copy(copy4)
        app('System Events').keystroke('V', using=k.command_down)

    if (keyboard.is_pressed('control+s+5')):
        clipboard.copy(copy5)
        app('System Events').keystroke('V', using=k.command_down)

    if (keyboard.is_pressed('control+s+6')):
        clipboard.copy(copy6)
        app('System Events').keystroke('V', using=k.command_down)

    if (keyboard.is_pressed('control+s+7')):
        clipboard.copy(copy7)
        app('System Events').keystroke('V', using=k.command_down)

    if (keyboard.is_pressed('control+s+8')):
        clipboard.copy(copy8)
        app('System Events').keystroke('V', using=k.command_down)

    if (keyboard.is_pressed('control+s+9')):
        clipboard.copy(copy9)
        app('System Events').keystroke('V', using=k.command_down)
def main():
    copyChecker()
    pasteChecker()
while (True):
    main()

非常感谢,任何帮助表示赞赏。

2 个答案:

答案 0 :(得分:1)

第39行最后需要一个小括号。 ]

答案 1 :(得分:0)

您是否检查过所有括号和括号是否已关闭?似乎你至少错过了一个,就在“def”之前,第40行。