0

我收到以下错误:

File "Question2.py", line 18
  except getopt.GetoptError as e:
SyntaxError: invalid syntax

它来自的代码部分:

 try:
     opts, args = getopt.getopt(argv, "c:t:", ["class=","term="]
 except getopt.GetoptError as e:
     print 'Question2.py -c <class> -t <term>'
     system.exit(2)
 for opt, arg in opts:
     if opt in ('c', 'class'):
             selectclass = arg
     if opt in ('t', 'term'):
              selectterm = arg

我想要做的是让命令行参数正常工作。我希望能够接受-cor-class-tor -term。我正在关注位于此处的教程。我不确定出了什么问题。

4

1 回答 1

2

您忘记了此行末尾的右括号:

opts, args = getopt.getopt(argv, "c:t:", ["class=","term="])
#                                                    here--^
于 2013-10-14T19:12:39.827 回答