尝试使用except时处理错误时的SyntaxError

时间:2018-04-16 21:16:50

标签: python error-handling syntax-error try-catch except

我正在尝试为我的ICT课程编写个人助理。我是python的初学者,我尝试过教程,但在使用SyntaxError时我得到except

这是剧本:

try:
    command = r.recognize_google(audio)
    print ('Your command was: ' + command + '/n'
    #loop back ca sa asculte pentru comenzi daca nu gaseI'ste recon speech
except sr.UnknownValueError:
    assistant(myCommand())

这就是错误:

File "/Users/dumitruvictor/Desktop/Assistant.py", line 31
    except (sr.UnknownValueError:
         ^

SyntaxError:语法无效

操作系统:Mac OS X

1 个答案:

答案 0 :(得分:0)

您需要关闭括号并在except

之后缩进该行
  except sr.UnknownValueError:
      assistant(myCommand())) # close parentheses, indent this line