来自scikit-learn网站上的classification example,我在使用optionparser执行部件后出现以下错误:
Usage: __main__.py [options]
__main__.py: error: no such option: -f
An exception has occurred, use %tb to see the full traceback.
SystemExit: 2
To exit: use 'exit', 'quit', or Ctrl-D.
%tb
命令提供以下输出:
---------------------------------------------------------------------------
BadOptionError Traceback (most recent call last)
/Users/kevinoost/anaconda/lib/python3.5/optparse.py in parse_args(self, args, values)
1385 try:
-> 1386 stop = self._process_args(largs, rargs, values)
1387 except (BadOptionError, OptionValueError) as err:
/Users/kevinoost/anaconda/lib/python3.5/optparse.py in _process_args(self, largs, rargs, values)
1429 # value(s) for the last one only)
-> 1430 self._process_short_opts(rargs, values)
1431 elif self.allow_interspersed_args:
/Users/kevinoost/anaconda/lib/python3.5/optparse.py in _process_short_opts(self, rargs, values)
1511 if not option:
-> 1512 raise BadOptionError(opt)
1513 if option.takes_value():
BadOptionError: no such option: -f
During handling of the above exception, another exception occurred:
SystemExit Traceback (most recent call last)
<ipython-input-10-960f3b27132a> in <module>()
66 "headers, signatures, and quoting.")
67
---> 68 (opts, args) = op.parse_args()
69 if len(args) > 0:
70 op.error("this script takes no arguments.")
/Users/kevinoost/anaconda/lib/python3.5/optparse.py in parse_args(self, args, values)
1386 stop = self._process_args(largs, rargs, values)
1387 except (BadOptionError, OptionValueError) as err:
-> 1388 self.error(str(err))
1389
1390 args = largs + rargs
/Users/kevinoost/anaconda/lib/python3.5/optparse.py in error(self, msg)
1566 """
1567 self.print_usage(sys.stderr)
-> 1568 self.exit(2, "%s: error: %s\n" % (self.get_prog_name(), msg))
1569
1570 def get_usage(self):
/Users/kevinoost/anaconda/lib/python3.5/optparse.py in exit(self, status, msg)
1556 if msg:
1557 sys.stderr.write(msg)
-> 1558 sys.exit(status)
1559
1560 def error(self, msg):
SystemExit: 2
根据docs,在Python 2.7版本中不推荐使用optparse;我正在使用Python 3。 我该怎么做才能解决这个问题?
谢谢,
问候,凯文