I'm getting the following error:
File "Question2.py", line 18
except getopt.GetoptError as e:
SyntaxError: invalid syntax
Section of code that it comes from:
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
What I am trying to do is get command line arguments working. I want to be able to accept -c
or -class
and -t
or -term
. I am following a tutorial located here . I am unsure what is going wrong.
You forgot a closing parenthesis at the end of this line:
opts, args = getopt.getopt(argv, "c:t:", ["class=","term="])
# here--^
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.