我收到以下错误:
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
我想要做的是让命令行参数正常工作。我希望能够接受-c
or-class
和-t
or -term
。我正在关注位于此处的教程。我不确定出了什么问题。